DataList控件功能很強大,他支持選擇、編輯,實現的方法也很簡單,不過最令人頭疼的就是它不像DataGrid控件一樣內置了分頁的功能,這么好的一個控件竟然不能分頁!!!確實是一個很讓人頭疼的事情。 不過,只是DataList沒有提供內置的分頁功能,但是并不表示,我們不能使用DataList控件來實現分頁,既然它不給我分頁功能,那只好自己動手了。 下面是全部原代碼,其實用到的方法和PHP中的分頁差不多,只是這里用的是DataAdapter與DataSet組合,而不是PHP中的SQL語句直接搞定。
default.aspx文件: <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="guestbook._default" %> <HTML> <HEAD> <title>中國BS網留言簿</title> <HTML> <HEAD> <title>DataList分頁</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> </HEAD> <body MS_POSITIONING="GridLayout"> <form method="post" action="default.aspx" runat="server" ID="Form1"> <table width="100%" border="0" cellpadding="2" cellspacing="0" align="center"> <tr> <td align="middle"> <asp:DataList ID="Myguest" RepeatColumns="1" Runat="server"> <ItemTemplate> <table class="gueststyleline" border="0" cellpadding="0" cellspacing="1" align="center" width="610"> <tr> <td> <table class="gueststyleline" border="0" cellpadding="0" cellspacing="1" align="center" width="610"> <tr> <td> <table width="100%" border="0" cellpadding="6" cellspacing="0" class="gueststylebg" align="center"> <tr> <td width="112" align="center" height="153" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" class="gueststylebg"> <tr> <td> <table border="0" cellspacing="0" cellpadding="0" align="center" height="25"> <tr> <td class="FILTER"> <div align="center"><font style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130; 0pt"><%# DataBinder.Eval(Container.DataItem,"name") %></font></div> </td> </tr> </table> <div align="center"><font style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130; 0pt"><img src="<%# DataBinder.Eval(Container.DataItem,"face") %>" width="80" height="90" align="middle"></font><br> <br> ★ <%# DataBinder.Eval(Container.DataItem,"sex") %> ★</div> </td> </tr> </table> </td> <td align="center" height="153" width="2"> <table class="gueststyleline" width="1" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="1"></td> </tr> </table> </td> <td height="33" valign="top" width="463"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="gueststylebg" style="TABLE-LAYOUT: fixed" height="20"> <tr> <td height="14" width="310"><img src="images/icon/subject.gif" width="15" height="15" alt="主題">:<%# DataBinder.Eval(Container.DataItem,"caption") %><br> </td> <td width="151" height="14"><font style="0pt"> <img src="images/icon/posttime.gif" width="16" height="15" alt="發表時間[北京時間]">:<%# DataBinder.Eval(Container.DataItem,"postdate") %></font></td> </tr> </table> <hr class="gueststylehr" size="0.1" width="100%"> <table width="100%" border="0" cellpadding="5" cellspacing="0" class="gueststylebg" height="45%" style="TABLE-LAYOUT: fixed"> <tr> <td valign="top" width="28" align="center"><img src="images/emot/1.gif" width="16" height="16"> </td> <td valign="top" width="94%" style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130; 0pt"> <%# DataBinder.Eval(Container.DataItem,"content") %> </td> </tr> </table> <table width="100%" border="0" cellpadding="4" cellspacing="0"> <tr> <td valign="top"> <hr class="gueststylehr" size="0.1" width="100%"> <a href="<%# DataBinder.Eval(Container.DataItem,"homepage") %>" target="_blank"><img src="images/icon/home.gif" width="44" height="16" border="0"></a> <a ] = CurrentPage; ListBind(); }
|