RadioButtonList Inside Repeater OnSelectedIndexCha

2019-08-05 16:43发布

问题:

I have a RadioButtonList inside a Repeater. I have AutoPostback set to "true" and the OnSelectedIndexChanged defined. When I selected a different radiobutton in my list the page does postback, but my defined OnSelectedIndexChanged event is not catching or firing. Not sure what I am missing. Here is my markup and codebehind:

回答1:

Use the repeater's itemcreated event to bind your eventhandler:

 protected void Repeater!_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                   e.item.FindControl("TaskRadioButtonList").SelectedIndexChanged += new EventHandler(TaskRadioButtonList_OnSelectedIndexChanged);

                }
        }