我在radiobuttonlist上申请onselectedindexchangedevent,但是当我点击
时
radiobuttton,radiobutton不选择运动,它选择,然后
取消选择。我还设置了postback = true。但它没有触发..
**.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;
}
答案 0 :(得分:2)
确保在发生回发时不重新加载gridview。 确保您的代码是这样的:
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostBack)
{
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
}
当触发单选按钮事件时,会再次触发Page_Load事件,但网格不会刷新,并且会触发Clicked方法。
答案 1 :(得分:0)
尝试更改您的代码:
RadioButtonList list= (RadioButtonList )row.FindControl("Radio");
要:
RadioButtonList list= (RadioButtonList )row.FindControl("RadioButtonList1");
由于您的gridview中没有名为“Radio”的控件。 希望这能解决你的问题。