0

我在单选按钮列表上应用 onselectedindexchangedevent 但是当我单击单选按钮时
,单选按钮没有选择移动,它选择,然后
取消选择。我还设置了 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;




        }
4

2 回答 2

2

确保在回发发生时您的 gridview 没有重新加载。确保您的代码是这样的:

protected void Page_Load(object sender, EventArgs e)
{
    If(!IsPostBack)
    {
       GridView1.DataSource = dataTable;
       GridView1.DataBind();
    }
}

当触发单选按钮事件时,再次触发 Page_Load 事件,但网格不会刷新并且 Clicked 方法将触发。

于 2012-07-05T12:33:57.253 回答
0

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.

于 2012-07-05T12:11:47.137 回答