我想通过手动添加列中的数据将数据放入数据网格视图,所以我该怎么做,请帮助我。
先谢谢你。
答案 0 :(得分:2)
尝试以下可能解决您的问题:
确保gridview(假设他ID =“gridview1”)在标记中并且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();
答案 1 :(得分:0)
如下:
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();