0

我想通过手动添加列将我的数据放入数据网格视图中,所以我该怎么做,请帮助我。

先感谢您。

4

2 回答 2

2

Try the following that might solve your problem:

Ensure that the gridview(assuming he ID="gridview1") is in the markup and that AutoGenerateColumns="True"

DataTable dataTable = new dataTable();
dataTable.Columns.Add("Column1");
dataTable.Columns.Add("Column2");
dataTable.Columns.Add("Column3");

DataRow dataRow = dataTable.NewRow();

dataRow["Column1"] = "";
dataRow["Column2"] = "";
dataRow["Column3"] = "";

dataTable.Rows.Add(dataRow);

gridview1.DataSource = datatable;
gridview1.DataBind();
于 2013-10-22T11:55:49.527 回答
0

What about something like:

var grd = new GridView();
grd.AutoGenerateColumns = false;
BoundField field = new BoundField();
field.DataField = "CustomerName";
field.HeaderText = Resources.GlobalResources.Customer;
DataControlField col = field;
grd.Columns.Add(col);
grd.DataSource = sortedCustomers;
grd.DataBind();
于 2013-10-22T11:54:34.317 回答