如何添加复选框,数据网格在vb.net [英] How to add checkbox to datagrid in vb.net
问题描述
我有一组显示数据库中的数据列的数据网格。我创建了数据表,并把它添加到数据网格,然后绑定源。这个伟大的工程,现在我想将列添加到具有复选框它网格的前面。
I have a datagrid with a set of columns showing data from a database. I create the datatable and add it to the datagrid and then bind the source. this works great and now I would like to add a column to the front of the grid that has checkbox in it.
我加入的时候我加入新行到在DataGrid中或之后显示我的数据绑定数据表到DataGrid?DataTable中的复选框
Do I add the checkbox when I am adding the new row to the datatable that is shown in the datagrid or after I databind the datatable to the datagrid?
使用:VB.Net时,Visual Studio 2012
Using: VB.Net, Visual Studio 2012
推荐答案
您可以使用复选框添加模板字段
you can add checkbox using template field
设置的AutoGenerateColumns属性设置为false。
Set AutoGenerateColumns attribute to false.
添加列标记的asp:DataGrid的标签
Add Column tag to asp:DataGrid tag.
现在添加ItemTemplate中列在
Now add itemtemplate inside columns
<asp:DataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkAll" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:DataGrid>
如果你想将其附加到数据表列然后u必须添加这样的
and if you want to attach it to datatable column then u have to add like this
<asp:DataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" OnCheckedChanged="chkStatus_OnChackedChanged" Checked='<%# Convert.ToBoolean(Eval("Approved")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:DataGrid>
这篇关于如何添加复选框,数据网格在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!