如何基于表中的列数据创建动态列 [英] how to create dynamic columns based on column data in a table
本文介绍了如何基于表中的列数据创建动态列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我,我想基于表格中的列数据动态创建gridview列.
pls help me i want to create gridview columns dynamically based on the column data in a table
推荐答案
嗨 皮拉(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[]
这篇关于如何基于表中的列数据创建动态列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文