因为如果在 .aspx 页面加载了 BoundField 或是 CommandField 等列值的话,则 gridview 所要显示的列数,字段内容 好像就固定了,那要加载另一张数据表也就不好在同一个页面操作了;
我想是在后台写代码加载 BoundField 或是 CommandField 以便在同一个 .aspx 页面针对不同要求对不同数据表进行操作,不知道这样行不行?
新手问问题,请大家多关照!!
这样试一下`~~~动态创建gridview的列
public void CreateGridViewColumn()
{
BoundField bf1 = new BoundField();
BoundField bf2 = new BoundField();
BoundField bf3 = new BoundField();
bf1.HeaderText = "Employee ID";
bf1.DataField = "EmployeeID";
bf1.ReadOnly = true;
bf1.SortExpression = "EmployeeID";
bf2.HeaderText = "First Name";
bf2.DataField = "FirstName";
bf2.SortExpression = "FirstName";
bf3.HeaderText = "Last Name";
bf3.DataField = "LastName";
bf3.SortExpression = "LastName";
CommandField cf = new CommandField();
cf.ButtonType = ButtonType.Button;
cf.ShowCancelButton = true;
cf.ShowEditButton = true;
GridView1.Columns.Add(bf1);
GridView1.Columns.Add(bf2);
GridView1.Columns.Add(bf3);
GridView1.Columns.Add(cf);
}