Reputation: 907
I have a grid-view on which each row consists check box, and there is a button outside the grid-view. when i check some rows on grid-view and clicking those button, i need to insert the checked rows details into another table of database. I have created the grid-view like this
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="student_name" HeaderText="student_name" SortExpression="student_name" />
<asp:BoundField DataField="student_id" HeaderText="student_id" SortExpression="student_id" ReadOnly="True" />
<asp:BoundField DataField="student_nric" HeaderText="student_nric" SortExpression="student_nric" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox AutoPostBack="false" Id="CheckBoxUpdate" runat="server" />
</ItemTemplate></asp:TemplateField>
</Columns>
</asp:GridView>
but dont know how to store the checked rows value to datatable. please help
Upvotes: 0
Views: 1347
Reputation: 2013
You can use a stringbuilder object to iterate through the rows of the checkbox and store the value. see this tutorial
http://www.codeproject.com/Articles/11207/Selecting-multiple-checkboxes-inside-a-GridView-co
Upvotes: 0
Reputation: 17604
On button click on which you want to save the values in the database.
Loop through earch row of the gridview.
Find the checkbox in that row
Check if it is checked or not
foreach (GridViewRow row in GridView1.Rows)
{
if (((CheckBox)row.FindControl("CheckBoxUpdate")).Checked)
{
//insert here
}
}
Here is a good link for the same
http://www.c-sharpcorner.com/Forums/Thread/201835/loop-through-gridview.aspx
Upvotes: 1