asp.net(c#版)添加DataRow数据列到DataTable控件
本文导语: asp.net实现添加DataRow数据列到DataTable控件。 代码: 代码示例: protected void Page_Load(object o, EventArgs e) { datagrid.DataSource = GetData(); DataBind(); } DataTable GetData() { DataTable data = new DataTable(); data.Columns.Add(new ...
asp.net实现添加DataRow数据列到DataTable控件。
代码:
protected void Page_Load(object o, EventArgs e) {
datagrid.DataSource = GetData();
DataBind();
}
DataTable GetData() {
DataTable data = new DataTable();
data.Columns.Add(new DataColumn("TheID", typeof(Int32)));
data.Columns.Add(new DataColumn("Name", typeof(string)));
data.Columns.Add(new DataColumn("TimeZone", typeof(string)));
DataRow dr;
dr = data.NewRow();
dr[0] = 1; dr[1] = "Washington"; dr[2] = "Pacific";
data.Rows.Add(dr);
dr = data.NewRow();
dr[0] = 2; dr[1] = "Utah"; dr[2] = "Mountain";
data.Rows.Add(dr);
dr = data.NewRow();
dr[0] = 3; dr[1] = "Wisconsin"; dr[2] = "Central";
data.Rows.Add(dr);
return data;
}