I m using GridView Controls to view the datas. For eg: I m getting column as username and displaying. Now i want to add Checkbox in gridview and want to store username and checkbox values in another table?

Member Avatar for h4ng4r18

Now that you have a Gridview with a Username Column - you can add a TemplateField containing the checkboxes (one per each row)

<asp:TemplateField HeaderText="ColumnHeaderHere" >
                                    <ItemTemplate>
                                        <asp:CheckBox ID="ChBxSaveUsername" runat="server"/>
                                    </ItemTemplate>
                                </asp:TemplateField>

A button is needed outside of the Grivew for the purpose of saving.

<asp:Button ID="BtnSaveUsernames" runat="server" OnClick="BtnSaveUsernames_Click"/>

From the code behind - you can work through the GVRows with a for statement or a foreach statement and record which of the rows contain a checkbox with checked = true. I would add this usernames (or maybe userIds if available?) into an array/list or a comma-separated string and then pass them back into the database via a Stored Procedure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.