更新时间:2022-12-09 11:49:48
嗨 皮拉(Pyla),
请执行以下操作:
1.在您的datagrid中设置AutoColumn = True
2.根据您的逻辑创建列,如
Hi Pyla,
Please do the following:
1. set AutoColumn=True in your datagrid
2. create columns based on your logic like
DataTable dt = new DataTable();
for (int c = 1; c <= 10; c++)
{
DataColumn dc = new DataColumn("Column" + c.ToString(), System.Type.GetType("System.String"));
dt.Columns.Add(dc);
}
GridView1.Datasource = dt;
GridView1.DataBind();
如有任何疑问,请让我知道.
如果对您有帮助,请提供投票.
谢谢,
Imdadhusen
Please do let me know, if you have any doubt.
Please provide Vote if this would be helpful to you.
Thanks,
Imdadhusen
公共静态数据表dtValues;
public static DataTable dtValues;
protected void CreateDataTable()
{
dtValues = new DataTable();
dtValues.Columns.Add("Id");
dtValues.Columns.Add("Item");
dtValues.Columns.Add("Rate");
dtValues.Columns.Add("Qty");
dtValues.Columns.Add("Amount");
}
这5列将动态创建
比添加它
these 5 columns will be created dynamically
than add it
gvOrders.DataSource = dtValues;
gvOrders.DataBind();
希望能奏效..
Amit
hope that works..
Amit
检查此代码项目文章如何在网格视图中动态创建列 [ ]
check this codeproject article how to create columns dynamically in a grid view[]