RadioButtonList SelectedIndexChanged事件未触发

时间:2012-05-11 22:59:59

标签: c# asp.net .net

我在asp视图控件上有radiobuttonlist。我在运行时动态填充radiobuttonlist。但是selectedindexchange事件没有触发。我尝试启用autopostback,page.oninit但它没有触发。

<asp:MultiView ID="MultiView1" runat="server">
            <asp:View ID="View1" runat="server">
                <br />
                <asp:Label ID="Label1" runat="server" Text="Label" CssClass="text"></asp:Label>
                &nbsp;<asp:Label ID="Label2" runat="server" Text="Label" CssClass="text"></asp:Label>

                <br />
               <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged1">
                </asp:RadioButtonList>
                <br />

                <p align="center">
                    <asp:Button ID="Button1" runat="server" Text="Previous" onclick="Button1_Click" Width="100px" />&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="Button2" runat="server" Text="Next" onclick="Button2_Click" Width="100px" />
                </p>


            </asp:View>
    </asp:MultiView>

我的onpage_load代码

if (!IsPostBack)
        {
            cnn.Open();
            cmd.Connection = cnn;

            cmd.CommandText = "SELECT ")";
            adp.SelectCommand = cmd;
            adp.Fill(ds);
            cnn.Close();

            dt = new DataTable("Answered");
            dt.Columns.Add("Serial", typeof(int));
            dt.Columns.Add("question", typeof(string));
            dt.Columns.Add("opt1", typeof(string));
            dt.Columns.Add("opt2", typeof(string));
            dt.Columns.Add("opt3", typeof(string));
            dt.Columns.Add("opt4", typeof(string));
            dt.Columns.Add("answer", typeof(int));
            dt.Columns.Add("selected", typeof(int));

            foreach (DataRow r in ds.Tables[0].Rows)
            {
                dr = dt.NewRow();
                dr["Serial"] = dt.Rows.Count + 1;
                dr["question"] = r["question"];
                dr["opt1"] = r["opt1"].ToString();
                dr["opt2"] = r["opt2"].ToString();
                dr["opt3"] = r["opt3"].ToString();
                dr["opt4"] = r["opt4"].ToString();
                dr["answer"] = Convert.ToInt16(r["answer"].ToString());
                dr["selected"] = -1;
                dt.Rows.Add(dr);
            }
            Session["Answered"] = dt;
            Show();
        }

2 个答案:

答案 0 :(得分:0)

可能是你遗失了RadioButtonList的事件处理程序。您可以在“设计”视图中通过双重克隆来创建它。这将为它创建事件处理程序。

答案 1 :(得分:0)

我很确定你还会在回发中重新定位RadioButtonList。只做if(!IsPostBack)

protected void Page_Load(Object sender, EventArgs e)
{
    if(!IsPostBack) 
        BindRadioButonList();
}

否则不会触发事件。