Click here to Skip to main content
15,300,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created a dynamic radiobuttonlist in Masterpage inherited page like this.this is working.

C#
RadioButtonList rbl = new RadioButtonList();
rbl.ID = "rblID";

//Add Items
rbl.Items.Add(new ListItem("One", "1"));
rbl.Items.Add(new ListItem("Two", "2"));
rbl.Items.Add(new ListItem("Three", "3"));

rbl.DataBind();
PlaceHolder1.Controls.Add(rbl);


i need to find the selected value of radiobuttonlist. i tried the below code, but it is not working.

C#
RadioButtonList rb = (RadioButtonList)FindControl("rblID"); 
TextBox1.Text = rb.SelectedValue;
Posted
Updated 24-Apr-12 2:28am
v4
Comments
Rahul Rajat Singh 24-Apr-12 8:30am
   
Just check whether you are doing the above mentioned stuff only on first time i.e. not on every postback.

RadioButtonList rb = (RadioButtonList)Master.FindControl("rblID"); 
TextBox1.Text = rb.SelectedValue;
   
Comments
Robymon 15-Feb-12 6:59am
   
not working. i am getting the following error.

System.NullReferenceException: Object reference not set to an instance of an object.
C++
RadioButtonList rbl = new RadioButtonList();
rbl.ID = "rblID";
rbl.AutopostBack="true";


rbl.Items.Add(new ListItem("One", "1"));
rbl.Items.Add(new ListItem("Two", "2"));
rbl.Items.Add(new ListItem("Three", "3"));
 
rbl.DataBind();
PlaceHolder1.Controls.Add(rbl);




C#
RadioButtonList rb = (RadioButtonList)FindControl("rblID");
TextBox1.Text = rb.SelectedValue; 
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900