2013-05-07 89 views
2

我有关于将BoundFiled添加到GridView的问题。所有关于框架.net 2,更高是不可能的。我有这样的代码以编程方式添加Boundfield

BoundField column = new BoundField(); 
column.HeaderText = "XX"; 
column.DataField = "ID"; 
column.SortExpression = "ID"; 
column.HeaderStyle.CssClass = "titletext"; 
column.ItemStyle.Width = Unit.Percentage(7); 

TableCell tc = new TableCell(); 
tc.Controls.Add(column); 

而且最后一个命令返回该错误消息

“的最佳重载的方法匹配 “System.Web.UI.ControlCollection.Add(System.Web.UI程序。控制)”有一些 参数无效”

这是我在C#中使用的是什么

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

这个例子是来自互联网,不工作,谢谢你的帮助。

回答

4

添加绑定列,因为这

BoundField boundField = new BoundField(); 
    boundField.DataField = "ID"; 
    boundField.HeaderText = "ID"; 
    boundField.SortExpression = "ID"; 
    boundField.HeaderStyle.CssClass = "titletext"; 
    boundField.ItemStyle.Width = Unit.Percentage(7); 
    GridView1.Columns.Add(boundField); 
    //bind gridview.. 

    bindgridview(); 

note: data source must contain the ID column 
+0

感谢,工作,如果我能在onrowcommand更改绑定列输入模式?我无法使用CommandField,因为重新加载所有数据,我可以编程方式将一个选定的数据更改为无CommandField的编辑模式。在HTML它看起来像这样,我改变​​文本到​​,但我不知道,我怎么在c#中做到这一点。谢谢 – user1173536 2013-05-07 06:00:41

+0

请为此提出另一个问题...但是从这里开始的所有细节我都明白您的要求和您面临的问题 – 2013-05-07 06:16:37