RadioButtonList and SelectedIndexChanged event solution

N

Nofear

Hi all !

I saw many post on the SelectedIndexChanged event not being PostedBack
when the property AutoPostback is set to true.

In fact, i done many test and my conclusion is :

When you add Listitems to the RadioButtonList, the value of each
ListItem must be UNIQUE.

Try this

protected System.Web.UI.WebControls.Label lblInfo;
protected System.Web.UI.WebControls.RadioButtonList radBtnList;

private void Page_Load(object sender, System.EventArgs e)
{
if(! Page.IsPostBack)
{
radBtnList.Items.Add(new ListItem("Entry 01", "01"); <= SAME
radBtnList.Items.Add(new ListItem("Entry 02", "02");
radBtnList.Items.Add(new ListItem("Entry 03", "01"); <= SAME
radBtnList.Items.Add(new ListItem("Entry 04", "04");
radBtnList.Items.Add(new ListItem("Entry 05", "05");
}
}

private void radBtnList_SelectedIndexChanged(object sender,
System.EventArgs e)
{
lblInfo.Text = "L'élément sélectionné a pour valeur texte : " +
radBtnList.SelectedItem.Text;
}

Entries 1 and 3 will not postback correctly.

This version postback correctly, because all ListItem Values are
differents

radBtnList.Items.Add(new ListItem("Entry 01", "01");
radBtnList.Items.Add(new ListItem("Entry 02", "02");
radBtnList.Items.Add(new ListItem("Entry 03", "03");
radBtnList.Items.Add(new ListItem("Entry 04", "04");
radBtnList.Items.Add(new ListItem("Entry 05", "05");

I hope this will help.

Nofear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top