Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have grid view with 4 columns 1st column has name of different departments fetched from a table in database. other 3 columns contain check box with column name add,edit & delete respectively. I want check for which department which check boxes were checked & make entry in database accordingly.
Can anyone help me. Its Urgent.

Thanks in advance
Posted

1 solution

<asp:gridview id="GridView1" runat="server" datasourceid="SqlDataSource1" width="400px" mode="hold" xmlns:asp="#unknown" />
    <Columns>

        <asp:TemplateField>

            <AlternatingItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </AlternatingItemTemplate>

            <ItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </ItemTemplate>

            <HeaderTemplate>

                <asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" />

            </HeaderTemplate>

            <HeaderStyle HorizontalAlign="Left" />

            <ItemStyle HorizontalAlign="Left" />

        </asp:TemplateField>

    </Columns>

</asp:GridView>


In Code Behind,-

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {

    if (e.Row.RowType == DataControlRowType.Header) {

      

        //and passing the ClientID of the Select All checkbox

        ((CheckBox)e.Row.FindControl("cbSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("cbSelectAll")).ClientID + "')");
// Write your own code here 
    }

}


Or you can have a look on these links,-
http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-vb[^]

Selecting multiple checkboxes inside a GridView control[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900