這裏是這樣使用ASP的GridView的例子:
// Create new DataTable.
DataTable dt = new DataTable();
// Total count of columns.
int colCount = 3;
// Add 3 columns.
for (int i = 0; i < colCount; i++)
{
dt.Columns.Add(new DataColumn("col" + i.ToString()));
}
// Add data to the datatable.
dt.Rows.Add(new object[] { "Empname", "Earnngs", "Amount" });
dt.Rows.Add(new object[] { "Austin", "Earnngs", "Amount" });
dt.Rows.Add(new object[] { "Austin", "df", "Amount" });
dt.Rows.Add(new object[] { "sdfsdf", "dsfdf", "df" });
dt.Rows.Add(new object[] { "Empdsfsdfname", "Earnngs", "df" });
// Loop through each column in the DataTable and set the column name to the data in the first row of data.
foreach (DataColumn dc in dt.Columns)
{
dc.ColumnName = dt.Rows[0][dc].ToString();
}
// Set the datasource of the grid.
this.GridView1.DataSource = dt;
// Bind the data to the grid.
this.GridView1.DataBind();
參見這些:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=VS.100).aspx
http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.aspx
,我會嘗試讓你know..anyways一個例子可以幫助更多的,和許多thanx您快速回復 – dodotnet