2

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" />
            <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>

2 Answers 2

7

Try using a <TemplateField /> instead

<asp:TemplateField>
    <ItemTemplate>
        <asp:CheckBox runat="server" ID="cbSelect"/>
    </ItemTemplate>
</asp:TemplateField>
Sign up to request clarification or add additional context in comments.

2 Comments

im getting an error type.system.web.ui.webcontrols.templateField does not have a public property name checkbox
You have to add the CheckBox to the ItemTemplate, like in Bala's example.
1

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.

1 Comment

im getting an error type.system.web.ui.webcontrols.templateField does not have a public property name checkbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.