Im trying to add a checkbox to a gridview so that users can select multiple items, but the checkbox is not showing up. Here is my code below. I dont have datafield b/c its tie into a particular column.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:CheckBoxField HeaderText="SELECT" />
<asp:BoundField DataField="ICAO" HeaderText="ICAO" />
<asp:BoundField DataField="IATA" HeaderText="IATA" />
<asp:BoundField DataField="AIRPORT_NAME" HeaderText="AIRPORT NAME" />
<asp:BoundField DataField="CITY" HeaderText="CITY" />
开发者_Python百科 <asp:BoundField DataField="COUNTRY" HeaderText="COUNTRY" />
<asp:BoundField DataField="REVISED_DATE" HeaderText="REVISED DATE" />
<asp:BoundField DataField="EMAIL_DATE" HeaderText="EMAIL DATE" />
</Columns>
</asp:GridView>
Try using a <TemplateField />
instead
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbSelect"/>
</ItemTemplate>
</asp:TemplateField>
Take a look here http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-vb
CheckBoxField is designed to work with a Boolean data field. That is, in order to use the CheckBoxField we must specify the underlying data field whose value is consulted to determine whether the rendered checkbox is checked. We cannot use the CheckBoxField to just include a column of unchecked checkboxes.
Just add an ItemTemplate
field and add a <asp:checkbox>
to it.
精彩评论