Accessing gridview

Last Reply on Jan 27, 2014 03:03 AM By Mudassar

Posted on Jan 27, 2014 03:03 AM

Hi,

I've a gridview and a radiobuttonlist

<asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True">
<Columns>
<asp:TemplateField HeaderText="IsApproved">
<ItemTemplate>
<asp:CheckBox ID="chkApproved" runat="server" CommandName="Approve" />

</ItemTemplate>

</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Approve" Value="1"></asp:ListItem>
<asp:ListItem Text="Reject" Value="2"></asp:ListItem>
</asp:RadioButtonList>

 

Gridview has a datasource that has four columns. Now on button click I want to insert the gridview data in the database, how to access the data in the columns,

protected void btnSubmit_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "1")
{
foreach (GridView row in GridView1.Rows)
{
var chk = row.FindControl("chkApproved") as CheckBox;
if (chk.Checked)
{
DataSet1TableAdapters.tbl_ApproveTableAdapter ta = new DataSet1TableAdapters.tbl_ApproveTableAdapter();
ta.Insert(*WHT TO WRITE HERE*);// TO access each column of tht particular row
}
}
}
}

 

Posted on Jan 27, 2014 03:03 AM
1. Please paste code using the Code button in your editor.


2. Paste only relevant code rather than whole page.
3. And also let us know the line throwing error, so that we can quickly get into action.

[CNP]