Reputation: 51
Could someone help me with this solution, stuck on it.
I have a list and filling radiobuttonlist with data, but I can't get selected value when i press submit button.
List<CustMobilePhonesEntity> cusMobile = GetCusMobile(Email);
RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber);
RadioButtonList1.DataSource = customerMobile;
RadioButtonList1.DataTextField = "PhoneNumber";
RadioButtonList1.DataValueField = "PhoneNumber";
RadioButtonList1.DataBind();
Label1.Text = RadioButtonList1.SelectedValue;
Any ideas what I'm doing wrong, thank you.
Upvotes: 1
Views: 3575
Reputation: 38200
First you need to check you are doing it in this fashion (If not the list is again binded with the DataSource when you click submit and the selection is lost)
if(! IsPostBack)
{
RadioButtonList1.DataSource = customerMobile;
RadioButtonList1.DataTextField = "PhoneNumber";
RadioButtonList1.DataValueField = "PhoneNumber";
RadioButtonList1.DataBind();
}
Also since you are binding RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber);
this won't be required (not clear if anything else).
Also see that ViewState
is enabled
Upvotes: 1