我想通过手动添加列将我的数据放入数据网格视图中,所以我该怎么做,请帮助我。
先感谢您。
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();
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();