事件不在ListView内的RadioButtonList上触发

时间:2012-05-30 19:58:25

标签: asp.net .net events

我在Listview的SlectedIndexChanged事件中使用RadioButtoList(在ListView内部)附加OnSelectedIndexChanged事件,当我运行程序时,单击RadioButton,即使我为此特定事件触发实现了所有代码,也没有事件触发。但是没有语法或编译错误。告诉我我用哪种类型的事件调用ListView或RadioButtonList?

.aspx代码:

<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>

代码背后:

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";        
} 

2 个答案:

答案 0 :(得分:0)

You OnSelectedIndexChanged位于列表视图中,而不是单选按钮列表。尝试将事件附件移动到单选按钮列表。

答案 1 :(得分:0)

ListView的{​​{1}}方法中,您需要将ItemDataBound事件绑定在那里。

selected