gpt4 book ai didi

c# - 以编程方式添加 Boundfield

转载 作者:行者123 更新时间:2023-11-30 20:57:58 25 4
gpt4 key购买 nike

我对将 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);

最后一个命令返回这个错误信息

"The best overloaded method match for 'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid arguments"

这是我在c#中使用的

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

此示例来自网络,无法运行,感谢帮助。

最佳答案

按此添加绑定(bind)列

  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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com