事件里面没有的ListView射击单选按钮列表 [英] Event not firing on RadioButtonList inside ListView

查看:124
本文介绍了事件里面没有的ListView射击单选按钮列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我附上的ListView SlectedIndexChanged事件与RadioButtoList OnSelectedIndexChanged事件(也就是里面的ListView),当我运行该程序,点击单选按钮,也没有事件火连我实现了所有code为这个特定的事件触发。然而,有没有语法或编译错误。告诉我,我叫什么类型的事件,这对无论是ListView控件或单选按钮列表?

的.aspx code:

 < ASP:ListView控件ID =ListView1的=服务器>
<&ItemTemplate中GT;
    < ASP:RadioButtonList的ID =radiobuttonlist4=服务器的AutoPostBack =真RepeatDirection =水平WIDTH =240像素onselectedindexchanged =选择>
        < ASP:ListItem的值=同意>< / ASP:ListItem的>
        < ASP:ListItem的值=不同意>< / ASP:ListItem的>
        < ASP:ListItem的值=strongagree>< / ASP:ListItem的>
        < ASP:ListItem的值=strongdisagree>< / ASP:ListItem的>
    < / ASP:RadioButtonList的>
< / ItemTemplate中>
< /列表视图>

code背后:

 保护无效的选择(对象发件人,EventArgs的发送)
{
    单选按钮列表listtt =(单选按钮列表)发送;
    ListViewItem的项目=(ListViewItem的)listtt.NamingContainer;    单选按钮列表ER =(单选按钮列表)item.FindControl(radiobuttonlist4);
    er.SelectedIndexChanged + =新的EventHandler(处理);
}公共无效手柄(对象发件人,EventArgs的发送)
{
    Label3.Text =hjeje;
}


解决方案
ListView控件的 的ItemDataBound 方法

,你需要在事件有约束力。

  VAR RDO = e.Row.FindControl(radiobuttonlist4)作为单选按钮;
rdo.OnSelectedIndexChanged + =新的EventHandler(选择);

I attach OnSelectedIndexChanged event with RadioButtoList (that is inside ListView)in SlectedIndexChanged event of listview , when I run the program, click on RadioButton, there no event fire even I implemented all code for this particular event firing. However there is no syntax or compilation error. Tell me what type of event I call against which either ListView or RadioButtonList?

.aspx Code:

<asp:ListView ID="ListView1" runat="server"  >
<itemtemplate>
    <asp:RadioButtonList ID="radiobuttonlist4" runat="server" AutoPostBack="true" RepeatDirection="Horizontal" Width="240px"  onselectedindexchanged="selected">
        <asp:ListItem Value="agree" ></asp:ListItem>
        <asp:ListItem Value="disagree"></asp:ListItem>
        <asp:ListItem Value="strongagree"></asp:ListItem>
        <asp:ListItem Value="strongdisagree"></asp:ListItem>
    </asp:RadioButtonList>
</itemtemplate>
</listview>

Code Behind:

protected void selected(object sender, EventArgs e)
{    
    RadioButtonList listtt = (RadioButtonList)sender;       
    ListViewItem item = (ListViewItem)listtt.NamingContainer;

    RadioButtonList er = (RadioButtonList)item.FindControl("radiobuttonlist4");    
    er.SelectedIndexChanged += new EventHandler(handle);                    
}

public void handle(object sender, EventArgs e)
{            
    Label3.Text = "hjeje";        
} 

解决方案

in your ListView's ItemDataBound method, you need to bind the selected event there.

var rdo = e.Row.FindControl("radiobuttonlist4") as RadioButton;
rdo.OnSelectedIndexChanged+= new EventHandler(selected);

这篇关于事件里面没有的ListView射击单选按钮列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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