Search code examples
asp.netrepeaterradiobuttonlist

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


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


Solution

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