Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式添加边界字段_C#_Asp.net - Fatal编程技术网

C# 以编程方式添加边界字段

C# 以编程方式添加边界字段,c#,asp.net,C#,Asp.net,我对将BoundField添加到GridView有疑问。关于framework.NET2,更高的版本是不可能的。我有这个密码 BoundField column = new BoundField(); column.HeaderText = "XX"; column.DataField = "ID"; column.SortExpression = "ID"; column.HeaderStyle.CssClass = "titletext"; column.ItemStyle.Width =

我对将BoundField添加到GridView有疑问。关于framework.NET2,更高的版本是不可能的。我有这个密码

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.Control)”有一些 无效参数“

这就是我在c中使用的#


此示例来自internet,不起作用,谢谢帮助。

添加绑定列如下

  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

谢谢,很好用,如果我能将onrowcommand上的BoundField更改为输入模式?我不能使用CommandField,因为这样可以重新加载所有数据,我可以通过编程将一个选定的数据更改为编辑模式,而不使用CommandField。在HTML中看起来是这样的,我将文本改为,但我不知道如何在c#中做到这一点。谢谢你提出另一个问题…但是从这里我无法了解你的要求和你面临的问题
  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