Dataview绑定实例(初学者可以看,很简单,但很实用的)

发表于:2007-06-30来源:作者:点击数: 标签:
%@ Page Language=C#% %@ Import Namespace=System.Data% script Language=C# Runat=Server public void Page_Load(Object src,EventArgs e) { int i; DataTable dt=new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn(编号)); dt.Columns.ADD(new
<%@ Page Language="C#"%>
<%@ Import Namespace="System.Data"%>
<script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
int i;
DataTable dt=new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("编号"));
dt.Columns.ADD(new datacolumn("用户名"));
for(i=1;i<8;i++)
{
dr=dt.NewRow();
dr[0]=Int32.ToString(i);
dr[1]="aspcn"+Int32.ToString(i);
dt.Rows.Add(dr);
}
DG1.DataSource = new DataView(dt);
DG1.DataBind();

}
</script>
<html>
<head>
<title></title>
</head>
<body>
<asp:DataGrid id="DG1" runat=server align=center HeaderStyle-BackColor="#aaaadd"/>
</body>
</html>

原文转自:http://www.ltesting.net