在gridview的末尾插入复选框列 [英] Insert checkbox column at the end of gridview

查看:26
本文介绍了在gridview的末尾插入复选框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GridView包含以编程方式添加的20列(DataTable,DataColumn,DataRow和DataSet).现在,我需要插入一个复选框列作为最后一列(21 st 列).我应该如何添加它?

My GridView contains 20 columns which are added programmatically (DataTable, DataColumn, DataRow and DataSet). Now I need to insert a checkbox column as the last column (21st column). How should I add it?

我尝试在.aspx文件中使用普通的模板字段(从设计"选项卡)添加,但在第一列中添加了一个复选框,在最后一列中添加了.

I tried adding with the usual Template Field (from design tab) in .aspx file but that adds a checkbox as the first column and not as the last one.

推荐答案

如果要使用 DataTable 绑定 GridView ,请在设置之前执行此操作GridView DataSource .

If you are binding your GridView using a DataTable, do this before you set the GridView DataSource.

dataTable.Columns.Add("Select", Type.GetType("System.Boolean"));

DemoGrid.DataSource = dataTable;
DemoGrid.DataBind();

foreach (GridViewRow row in DemoGrid.Rows)
{
    //check box is the first control on the last cell.
    CheckBox check = row.Cells[row.Cells.Count - 1].Controls[0] as CheckBox;
    check.Enabled = true;
}

在不相关的旁注中,请注意,您的 asp:GridView 实际上是自动生成的.

On an unrelated side note, please note that your asp:GridView is in fact AutoGenerated.

这篇关于在gridview的末尾插入复选框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆