0

我在 asp 视图控件上有单选按钮列表。我在运行时动态填充单选按钮列表。但 selectedindexchange 事件未触发。我尝试启用自动回发,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();
        }
4

2 回答 2

0

May be you lost event handler for your RadioButtonList. You can create it by double cliking on it in Design view. this will create event handler for it.

于 2012-05-11T23:08:18.677 回答
0

我相当确定您RadioButtonList在回发时也重新绑定了数据。只做那个if(!IsPostBack)

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

否则不会触发事件。

于 2012-05-11T23:10:32.560 回答