日期:2014-05-18  浏览次数:20513 次

跪求~如何动态循环创建gridview的列
各位好兄弟们,帮我支招
gridview是后台生成的,但是要创建的列不能确定
是动态的,
一般是DataColumn dcol = new DataColumn(ID, typeof(System.Int32));
这样来添加一列,但是列数不固定,
 也许有
dcol
dco2
dco3
dco4
~~~等等列
我用了一个数组
for(int i = 0;i<count;i++)
{
  string[i] = "col" + i.ToString();
  DataColumn string[i] = new DataColumn(string[i], typeof(System.Int32)); //就是这里第一个string[i]报错
}

怎么循环增加列呢,谢谢
用服务器端控件table也行啊

------解决方案--------------------
for(int i = 0;i <count;i++) 

string[i] = "col" + i.ToString(); 
DataColumn string[i] = new DataColumn(string[i], System.Type.GetType("System.Int32")); //就是这里第一个string[i]报错 


---------
try this above
------解决方案--------------------
No, No, No,
You cannot indicate variable's name in run time!
try this as follows:

DataColumn[] dcs[] = new DataColumn[count - 1];
for(int i = 0;i <count;i++) 

string[i] = "col" + i.ToString(); 
dcs[i] = new DataColumn(string[i], typeof(System.Int32)); //就是这里第一个string[i]报错 
}
------解决方案--------------------
ITemplate