首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >selectedindexchanged事件未在单选按钮列表上触发

selectedindexchanged事件未在单选按钮列表上触发
EN

Stack Overflow用户
提问于 2012-07-05 19:34:44
回答 2查看 2.9K关注 0票数 0

我在单选按钮列表上应用了onselectedindexchangedevent,但当我单击

代码语言:javascript
复制
  radiobuttton  ,radiobutton is not selecting for a movement, it select,and then
代码语言:javascript
复制
  deselect .I also set postback=true.but it is not firing ..
代码语言:javascript
复制
**.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;




        }
EN

回答 2

Stack Overflow用户

发布于 2012-07-05 20:33:57

确保回发发生时网格视图没有重新加载。确保您的代码如下所示:

代码语言:javascript
复制
protected void Page_Load(object sender, EventArgs e)
{
    If(!IsPostBack)
    {
       GridView1.DataSource = dataTable;
       GridView1.DataBind();
    }
}

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

票数 2
EN

Stack Overflow用户

发布于 2012-07-05 20:11:47

尝试更改您的代码:

代码语言:javascript
复制
RadioButtonList list= (RadioButtonList )row.FindControl("Radio");

至:

代码语言:javascript
复制
RadioButtonList list= (RadioButtonList )row.FindControl("RadioButtonList1");

因为在您的网格视图中没有名为“Radio”的控件。希望这能解决你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11343496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档