I wrote code for asp.net c#
I use grid view to display information from database and I am using checkbox to select the data , but the problem How can save these data I selected in array , then save it to data base .
this my code
the grid view
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Q_ID" DataField="Q_Multiple_ID" />
<asp:BoundField HeaderText="The Question" DataField="Multiple_Question" />
</Columns>
</asp:GridView>
the c#
protected void GetSelectedRecords(object sender, EventArgs e) {
string selected = "";
foreach (GridViewRow row in GridView3.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chkSelect");
// get the selected AutoId and cells text
if (chk.Checked)
{
string QID = GridView3.DataKeys[row.DataItemIndex].Values["Q_Multiple_ID"].ToString();
selected += QID;
test.Text = selected;
}
}
test.Text = selected;
}
Aucun commentaire:
Enregistrer un commentaire