2

我对将 BoundFiled 添加到 GridView 有疑问。关于框架 .net 2,更高是不可能的。我有这个代码

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# 中使用的

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

此示例来自互联网,无法正常工作,感谢帮助。

4

1 回答 1

5

像这样添加绑定列

  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
于 2013-05-07T05:50:42.613 回答