在数据表中添加按钮列

3
我正在尝试在数据表中插入一个按钮列,但它显示出错。请问有什么帮助吗?
        ButtonColumn col = new ButtonColumn();
        col.CommandName = "select";
        col.ButtonType = ButtonColumnType.LinkButton;
        col.HeaderText = "Edit";
        dt.Columns.Add(col);

2
  1. 你真的没有将数据添加到 datatable,你需要将其添加到 datagrid
  2. 请问你遇到了什么错误或者我们需要猜测?
- Renatas M.
如果您得到了想要的信息,请不要忘记将答案标记为已接受... - Pranay Rana
2个回答

5
在DataTable中添加按钮列是不可能的,这很奇怪。
DataTable DataColumn DataType属性支持以下基本.NET Framework数据类型:
1.布尔型
2.字节型
3.Char型
4.日期时间型
5.十进制型
6.Double型
7.Int16型
8.Int32型
9.Int64型
10.SByte型
11.Single型
12.String型
13.TimeSpan型
14.UInt16型
15.UInt32型
16.UInt64型
以下是添加列的示例代码:
DataTable workTable = new DataTable("Customers"); 
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = true;

我认为OP实际上是想将列添加到datagrid-datasource中的datatable,这就是为什么 :) - Renatas M.
@Reniuz - 我正在等待OP方面的更新,以便我可以根据那个更新我的答案... - Pranay Rana
以上列表中缺少 Byte[]。http://msdn.microsoft.com/zh-cn/library/system.data.datacolumn.datatype.aspx - Tim Schmelter

5
您只能在 DataGrid 上添加 button,而不能在 DataTable 上添加。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接