OnSelectedIndexChanged事件未触发 [英] OnSelectedIndexChanged event not firing

查看:218
本文介绍了OnSelectedIndexChanged事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在gridview中使用了单选按钮,我只希望选中一个单选按钮,所以我使用了以下代码''

hi all
i used radio buttons in gridview i want only single radio button should be checked so i used following code''

<asp:GridView ID="GridView2" runat="server" ShowHeader="False" AutoGenerateColumns="False"

                   onrowcommand="GridView2_RowCommand"  Width="100%" CellPadding="4"

                   ForeColor="#333333" GridLines="None">

                   <AlternatingRowStyle BackColor="White" />
                   <Columns>
                     <asp:TemplateField>


               <ItemTemplate>
                 
                   <asp:RadioButton ID="rblselect" runat="server" Enabled="true" RepeatDirection="Horizontal"  Width="5px" OnSelectedIndexChanged="rbSelector_CheckedChanged" />
                   </ItemTemplate>


后面的代码


code behind

protected void rbSelector_CheckedChanged(object sender, System.EventArgs e)
       {
           //Clear the existing selected row
           foreach (GridViewRow oldrow in GridView2.Rows)
           {
               ((RadioButton)oldrow.FindControl("rblselct")).Checked = false;
           }

           //Set the new selected row
           RadioButton rb = (RadioButton)sender;
           GridViewRow row = (GridViewRow)rb.NamingContainer;
           ((RadioButton)row.FindControl("rblselect")).Checked = true;
       }


更改单选按钮后,任何人都可以提示我哪里出错了吗?


can any one suggest me where i went wrong event is not firing at all after changing radio button

推荐答案

尝试设置
Try setting the AutoPostback[^] to true.


hi,
您需要像这样将GroupName添加到单选按钮:
hi ,
you need to add the GroupName to the radio button like this:
<asp:radiobutton id="rblselect" runat="server" enabled="true" repeatdirection="Horizontal" xmlns:asp="#unknown">
        Width="5px" OnSelectedIndexChanged="rbSelector_CheckedChanged" GroupName="Radio" /></asp:radiobutton>


表示它只会同时检查一个单选按钮


means it will check only one radio button at the same time




您需要将RadioButton的AutoPostBack属性设置为True.
Hi,

You need to set AutoPostBack Property of RadioButton to True.


这篇关于OnSelectedIndexChanged事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆