我对将BoundFiled添加到GridView有疑问。关于framework .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;


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

最佳答案

为此添加绑定列

  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

关于c# - 以编程方式添加Boundfield,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16412005/

10-11 05:18