1.建立用户控件Pager.ascx
1.1 html
</ASP:LABEL></TD> <TD><ASP:BUTTON ID="btnGo" RUNAT="server" TEXT="转到" COMMANDARGUMENT="Go" ToolTip="转到"></ASP:BUTTON></TD> <TD><asp:LinkButton id="btnNextPage" runat="server" CommandArgument="Next">下一页</asp:LinkButton></TD> <TD><asp:LinkButton id="btnLastPage" runat="server" CommandArgument="Last">最后一页</asp:LinkButton></TD> </TR> </TABLE>
1.2 cs代码
;//可以在web.config中配置 public event System.EventHandler NavigationClick; private void Page_Load(object sender, System.EventArgs e) { this.txtCurrentPage.Attributes.Add("onkeypress","callButtonEvent();"); this.btnGo.Attributes.Add("onclick","check();"); if(!this.IsPostBack) { SetStyle(); SetEnable(); } } Web Form Designer generated code btnGo_Click SetStyle SetEnable Property Property }
2.建立DataGridPage.aspx 3.copy如下html代码
<HTML> <HEAD> <title>DataGridPage</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 632px; POSITION: absolute; TOP: 40px" runat="server"></asp:datagrid><uc1:pager id="Pager1" runat="server"></uc1:pager><asp:datalist id="DataList1" style="Z-INDEX: 102; LEFT: 264px; POSITION: absolute; TOP: 40px" runat="server"> <ItemTemplate> <table> <tr> <td>用户ID:</td> <td><%# DataBinder.Eval(Container.DataItem, "UserID") %></td> <td>用户名:</td> <td><%# DataBinder.Eval(Container.DataItem, "UserName") %></td> </tr> </table> </ItemTemplate> </asp:datalist> <asp:repeater id="Repeater1" runat="server"> <HEADERTEMPLATE> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td>用户ID</td> <td>用户名:</td> </tr> </HEADERTEMPLATE> <ITEMTEMPLATE> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "UserID")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "UserName") %></td> </tr> </ITEMTEMPLATE> <FOOTERTEMPLATE> </table> </FOOTERTEMPLATE> </asp:repeater></form> </body> </HTML>
4.拖入用户控件Pager.ascx 5.copy如下cs代码
public class DataGridPage : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected UserControl.Pager Pager1;//定义用户控件,根据用户控件所在目录做适当的调整 protected System.Web.UI.WebControls.DataList DataList1; protected System.Web.UI.WebControls.Repeater Repeater1; public static string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; private void Page_Load(object sender, System.EventArgs e) { if (!this.IsPostBack) { BindData(); } } Bind Data ExecSPDataSet GetList property Web Form Designer generated code private void Pager1_NavigationClick(object sender, EventArgs e) { BindData(); } }
6.测试表结构
) COLLATE Chinese_PRC_CI_AS NULL , [Enabled] [bit] NULL ) ON [PRIMARY] GO
7.测试存储过程
) END GO -- declare @aa int -- exec tp_Fetch_List 1,10,'',@aa out ,'1=1' -- select @aa