Datagrid
This is the way the nine mother-in-law gave:
Complete Example:
Mygrid.ascx:
<%@ control language= "C #" autoeventwireup= "false" codebehind= "MyGrid.ascx.cs" inherits= "XsStudio.test.MyGrid" Targetschema= "Http://schemas.microsoft.com/intellisense/ie5"%>
<asp:datagrid id= "DATAGRID1" runat= "Server" showheader= "False" allowpaging= "True" pagesize= "3" ></asp:d Atagrid>
MyGrid.ascx.cs
Namespace test
{
Using System;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
<summary>
Summary description of the Mygrid.
</summary>
public class MyGrid:System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
}
public void LoadData (string id)
{
DataTable dt = new DataTable ();
dt. Columns.Add ("SN");
dt. Columns[0]. autoincrementseed=1;
dt. Columns[0]. AutoIncrement = true;
dt. Columns.Add ("AAA");
dt. Columns.Add ("BBB");
dt. Columns.Add ("CCC");
dt. Rows.Add (New string[]{"1", ID, "435689", System.DateTime.Now.ToString ());
dt. Rows.Add (New string[]{"2", ID, "34535", System.DateTime.Now.ToString ());
dt. Rows.Add (New string[]{"3", ID, "4456", System.DateTime.Now.ToString ());
dt. Rows.Add (New string[]{"4", ID, "64563", System.DateTime.Now.ToString ());
dt. Rows.Add (New string[]{"5", ID, "84535", System.DateTime.Now.ToString ());
this. DataGrid1.DataSource = DT;
this. Datagrid1.databind ();
Viewstate[this. Clientid+ "_id"] = ID;
}
private void Datagrid1_pageindexchanged (object source, DataGridPageChangedEventArgs e)
{
This. Datagrid1.currentpageindex = E.newpageindex;
LoadData (viewstate[this. Clientid+ "_id"]. ToString ());
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
This. Datagrid1.pageindexchanged+=new Datagridpagechangedeventhandler (datagrid1_pageindexchanged);
}
#endregion
}
}
WebForm1.aspx:
<%@ Page language= "C #" codebehind= "WebForm1.aspx.cs" autoeventwireup= "false" inherits= "XsStudio.test.WebForm1" Validaterequest=false%>
<%@ Register tagprefix= "uc1" tagname= "Mygrid" src= "Mygrid.ascx"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<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 bgcolor= "#cccccc" ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<asp:datalist id= "DataList1" style= "Z-INDEX:101; left:8px; Position:absolute; top:8px "runat=" Server >
<ItemTemplate>
<asp:textbox id= "TextBox1" runat= "server" text= ' <%# DataBinder.Eval (Container.DataItem, "id")%> ' ></ Asp:textbox>
<asp:textbox id= "Textbox2" runat= "server" text= ' <%# DataBinder.Eval (Container.DataItem, "Smallpicpath")%> ' ></asp:TextBox>
<uc1:mygrid id= "MYGRID1" runat= "Server" ></uc1:MyGrid><br/>
</ItemTemplate>
</asp:DataList>
</form>
<script language= "JavaScript" >
</script>
</body>
</HTML>
WebForm1.aspx.cs:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
U