用DataList如何实现分页!

bfqyvek 2004-08-27 01:56:26
如果我用以下代码。可我想有分页的,应如何做呢?请各位大哥指点一下。谢谢!

%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>


<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e) {

SqlConnection myConnection = new SqlConnection("server=(local);database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "书名");

MyDataList.DataSource = ds.Tables["书名"].DefaultView;
MyDataList.DataBind();
}

</script>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">

<!-- #include virtual="header.inc" -->

<ASP:DataList id="MyDataList" RepeatColumns="3" RepeatDirection="Horizontal" runat="server" HorizontalAlign="Center">
<FooterStyle HorizontalAlign="Center"></FooterStyle>

<ItemTemplate>

<div style="padding:15,15,15,15;font-size:10.5pt;font-family:宋体">

<div style="font:12pt 宋体;color:darkred">
<i><b><%# DataBinder.Eval(Container.DataItem, "title") %></i></b>
</div>

<br>

<b>书名 ID:</b><%# DataBinder.Eval(Container.DataItem, "title_id") %><br>
<b>类别:</b><%# DataBinder.Eval(Container.DataItem, "type") %><br>
<b>出版商 ID:</b><%# DataBinder.Eval(Container.DataItem, "pub_id") %><br>
<b>价格:</b><%# DataBinder.Eval(Container.DataItem, "price", "$ {0}") %><p>

</div>

</ItemTemplate>

</ASP:DataList>

<!-- #include virtual="footer.inc" -->

</body>
</html>

...全文
111 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2004-08-27
  • 打赏
  • 举报
回复
here is C# example:

Paging a DataList
http://www.csharphelp.com/archives3/archive544.html
saucer 2004-08-27
  • 打赏
  • 举报
回复
you need to write your own paging code, but see

Ask the DotNetJunkies: DataList Paging
http://www.dotnetjunkies.com/Tutorial/70E24E50-C179-4563-B053-2742516BF05B.dcik

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧