◆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;
///
/// MyGrid 的摘要说明。
///
public class MyGrid : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
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());
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
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" %>
JavaScript name=vs_defaultClientScript>
◆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;
using Microsoft.Web.UI.WebControls;
using System.Data.OleDb;
namespace XsStudio.test
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText Text1;
protected System.Web.UI.WebControls.DataList DataList1;
本新闻共3页,当前在第1页 1 2 3