Reputation: 79
I apply onselectedindexchangedevent on radiobuttonlist but when I click on
radiobuttton ,radiobutton is not selecting for a movement, it select,and then
deselect .I also set postback=true.but it is not firing ..
**.aspx**
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="true"RepeatDirection="Horizontal"OnSelectedIndexChanged="clicked">
<asp:ListItem Value="agree" Selected="True" ></asp:ListItem>
<asp:ListItem Value="agree"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
**.aspx.cs**
public void clicked(object sender, EventArgs arg)
{
test t = new test();
questiondal d = new questiondal();
GridViewRow row= (( RadioButtonList )sender).NamingContainer as GridViewRow;
RadioButtonList list= (RadioButtonList )row.FindControl("Radio");
list.SelectedIndexChanged();
Label4.Text= list.SelectedValue;
}
Upvotes: 0
Views: 2988
Reputation: 8818
Ensure that you gridview is not reloading when the postback occurs. Ensure that your code is something like this:
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostBack)
{
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
}
When the radio button event is fired the Page_Load event is fired again but the grid won't refresh and the Clicked method will fire.
Upvotes: 2
Reputation:
Try change your code:
RadioButtonList list= (RadioButtonList )row.FindControl("Radio");
To:
RadioButtonList list= (RadioButtonList )row.FindControl("RadioButtonList1");
As there is no control in your gridview named 'Radio'. Hope this will solve your problem.
Upvotes: 0