2011-09-13 109 views
1

有人可以帮我解决这个问题,Radiobuttonlist选定的值

我有一个列表,并用数据填充单选按钮列表,但当我按下提交按钮时,我无法获得选定的值。

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; 

任何想法我做错了,谢谢。

+1

你'内如果(!的IsPostBack)'其他条件的选择将失去 – V4Vendetta

+0

工作解决相关问题的 http://stackoverflow.com/questions结合他们/ 378620 /越来越选定值从radiobuttonlist – Olle89

+0

@ V4Vemdetta,是的,但得到空:( – Renaldas

回答

1

首先,你需要检查你以这种方式做(如果不在名单再次与数据源绑定,当你点击提交,并选择丢失)

if(! IsPostBack) 
{ 
    RadioButtonList1.DataSource = customerMobile; 
    RadioButtonList1.DataTextField = "PhoneNumber"; 
    RadioButtonList1.DataValueField = "PhoneNumber"; 
    RadioButtonList1.DataBind(); 
} 

此外,由于要绑定RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber);这不会被要求(如果还有其他问题,则不清楚)。

也看到ViewState启用

+0

RadioButtonList1.Items.Add(customerMobile [0] .PhoneNumber);是的,删除。 – Renaldas

+0

你已经有了DataSource为什么你要说'.Add'? – V4Vendetta

+0

我删除了.Add,这是错误的,但也不能得到选定的值 – Renaldas

相关问题