Search code examples
c#asp.netradiobuttonlistselectedindexchanged

SelectedIndexChanged for multiple RadionButtonList


I have 3 RadionButtonList that are wired to same SelectedIndexChanged event, intentionally. Is there a way to ascertain in the event which RadioButtonList just had one of its items clicked programmatically?


Solution

  • You can use the ID attribute of your RadioButtonList objects to do this, and just get the ID of the sender object whenever the event is fired.

    protected void RadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
    {
        string listName = ((RadioButtonList)sender).ID
        // listName = RadioButtonList1 or RadioButtonList2 or whatever the ID is set to.
    
        if (listName == "RadioButtonList1")
        {
            // Rest of your code goes here, now that you know which RadioButtonList the event was fired from
        }
    }