开发者

Radiobuttonlist selected value

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";
                RadioBu开发者_StackOverflow中文版ttonList1.DataValueField = "PhoneNumber";
                RadioButtonList1.DataBind();


Label1.Text = RadioButtonList1.SelectedValue;

Any ideas what I'm doing wrong, thank you.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜