itearation through gridview
Posted
by
user1405508
on Stack Overflow
See other posts from Stack Overflow
or by user1405508
Published on 2012-06-07T09:11:19Z
Indexed on
2012/06/07
16:40 UTC
Read the original article
Hit count: 218
I want to get cell value from gridview,but empty string is returned .I am implemented
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;
}
}
© Stack Overflow or respective owner