Get selected radio button list value from radio buttons inside a Repeater

obautista picture obautista · Jul 15, 2011 · Viewed 23.1k times · Source

I have a radiobuttonlist inside a repeater. I am showing a screenshot of what this looks like. I have column headers inside the header template of the repeater. In the item template, I have the 4 fields/columns. The 3rd field is a radio button list. If, for example, I select the "Yes" radio button in the "Test Task 2" row - I need to postback and save the value of that record (back to a database). My repeater could potentially display many rows of fields and radio button lists.

screenshot

Answer

Jith picture Jith · Jul 15, 2011

Try this


protected void btnSave_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in Repeater1.Items)
        {
            // Checking the item is a data item
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                var rdbList = item.FindControl("RadioButtonList1") as RadioButtonList;
                // Get the selected value
                string selected = rdbList.SelectedValue;
            }
        }
    }