Reputation: 35
I want to get cell value from gridview,but empty string is returned .I am implemented
all code in selectedindexchanged event of radiobuttonlist .I iterate through gridview
and access cell by code .but problem is stll remaining.I used three itemtemplate ,each
has one elemnt so that each element get its own coulmn
.aspx
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("qno") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("description")
%>'>
</ItemTemplate>
</asp:TemplateField>
<asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal"
runat="server" OnSelectedIndexChanged="changed" AutoPostBack="true" >
<asp:ListItem Value="agree" Selected="True" >
</asp:ListItem>
<asp:ListItem
Value="disagree">
</asp:ListItem>
<asp:ListItem Value="strongagree">
</asp:ListItem>
<asp:ListItem Value="strondisagree">
</asp:ListItem>
</asp:RadioButtonList>
</Columns>
</asp:GridView>
<asp:Label ID="Labe11" runat="server" ></asp:Label>
Code behind: public void changed(object sender, EventArgs e) {
for(int i=0;i<GridView2.Rows.Count;i++)
{
string labtext;
RadioButtonList list =
GridView2.Rows[i].Cells[2].FindControl("RadioButtonList1") as RadioButtonList;
labtext= GridView2.Rows[i].Cells[0].Text;
Label1.Text = labtext;
}
}
Upvotes: 0
Views: 1735
Reputation: 825
I think you're looking for the RowUpdating event for the gridview. The code below is from a project a I worked on a couple of years ago, where I had to grab the value from a combo-box within a gridview. Hopefully this will get you closer to a solution.
protected void gvReconciliation_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList dropDownListUser = gvReconciliation.Rows[e.RowIndex].FindControl("ddlSourceEdit") as DropDownList;
e.NewValues["source"] = dropDownListUser.SelectedItem.Text;
}
My controls were bound to an object data source so that's why you see the e.NewValues["source"]
in there. "Source" was the bound column name in my ObjectDataSource.
Upvotes: 3