C# – ASP.Net RadioButtonList SelectedIndexChanged event not firing

asp.netc

I'm building a dynamic RadioButtonList to list all of the records for a particular search item and allow the user to select the relevant option. The problem I'm having however, is that the SelectedInhdexChanged event is never firing.

I've tried initialising the RadioButtonList and assigning its event handler in the page_load and page_init methods. I've also tried dragging the RadioButtonList onto the page and double- clicking it to create the event handler that way- but still no luck.

Any ideas? I've pasted my code below for you to have a look:

Here's my Page_Load and event handler method:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            measureDropdown = loadDropdown("GetMeasuringTypes", measureDropdown);
            categoryDropdown = loadDropdown("GetCategories", categoryDropdown);
        }

        rBtn = new RadioButtonList();
        rBtn.CausesValidation = true;
        rBtn.SelectedIndexChanged += new EventHandler(rBtn_SelectedIndexChanged);
    }

    void rBtn_SelectedIndexChanged(object sender, EventArgs e)
    {
        moreThanOneLbl.Text = "Woohoo!";
    }

Here's how I assign the list items to the RadioButtonList (from a datatable):

foreach (DataRow row in table.Rows)
            {
                ListItem li = new ListItem();
                li.Value = row[0].ToString();
                li.Text = row[1].ToString() + ": " + row[2].ToString();
                //rBtn.Items.Add(li);
                RadioButtonList1.Items.Add(li);

            }

Best Answer

Try setting the AutoPostBack property to true.

rBtn.AutoPostBack = true
Related Topic