Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RadioButton列出所选值_C#_Asp.net_Radiobuttonlist - Fatal编程技术网

C# RadioButton列出所选值

C# RadioButton列出所选值,c#,asp.net,radiobuttonlist,C#,Asp.net,Radiobuttonlist,有人能帮我解决这个问题吗 我有一个列表,并用数据填充radiobuttonlist,但当我按下submit按钮时,无法获得所选值 List<CustMobilePhonesEntity> cusMobile = GetCusMobile(Email); RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber); RadioButtonList1.DataSource = customer

有人能帮我解决这个问题吗

我有一个列表,并用数据填充radiobuttonlist,但当我按下submit按钮时,无法获得所选值

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;
List cusMobile=GetCusMobile(电子邮件);
RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber);
RadioButtonList1.DataSource=customerMobile;
RadioButtonList1.DataTextField=“PhoneNumber”;
RadioButtonList1.DataValueField=“PhoneNumber”;
RadioButtonList1.DataBind();
Label1.Text=RadioButtonList1.SelectedValue;

任何关于我做错了什么的想法,谢谢。

首先,您需要检查您是否以这种方式进行操作(如果没有,当您单击“提交”时,列表将再次与数据源绑定,并且选择将丢失)

另外,因为您正在绑定
RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber)这将不是必需的(不清楚是否还有其他内容)


另请参见启用了
ViewState

首先,您需要检查您是否以这种方式执行此操作(如果未启用,则在单击“提交”时列表将再次与数据源绑定,并且选择将丢失)

另外,因为您正在绑定
RadioButtonList1.Items.Add(customerMobile[0].PhoneNumber)这将不是必需的(不清楚是否还有其他内容)


另请查看
ViewState
已启用

是否在
中绑定它们如果(!IsPostBack)
条件不满足,则选择将丢失相关问题的有效解决方案@V4Vemdetta,是但变为空:(@Olle89尝试过,也没有任何效果,当我手动将项目添加到radiobuttonlist时,效果很好,但我需要从列表中了解您是否在
中绑定它们,如果(!IsPostBack)
条件,否则选择将丢失相关问题的工作解决方案@V4Vemdetta,是但变为空:(@Olle89尝试过,也没有任何效果,当我手动将项目添加到radiobuttonlist时,效果很好,但我需要从listRadioButtonList1.items.add(customerMobile[0].PhoneNumber)中删除项目);是的,删除了。您已经有了数据源。为什么要说
。添加
?我删除了。添加,这是错误的,但也无法获得所选值。您是在按钮单击处理程序中设置标签文本还是在页面加载上设置标签文本?您是在该代码块中再次绑定它吗?抱歉,我只是打扰您了,这是我的错误,因为我正在构建这是一个问题,正在关闭移动应用程序,并在母版页上禁用了ViewState。现在一切正常。非常感谢!RadioButtonList1.Items.Add(customerMobile[0]。PhoneNumber);是的,删除了。您已经有了数据源。为什么要说
。添加
?我删除了。添加,这是错误的,但也无法获得所选值。您是在按钮单击处理程序中设置标签文本还是在页面加载上设置标签文本?您是在该代码块中再次绑定它吗?抱歉,我只是打扰您了,这是我的错误,因为我正在构建正在关闭移动应用程序,并在母版页上禁用ViewState,这就是问题所在。现在一切正常。非常感谢!
if(! IsPostBack)
{
   RadioButtonList1.DataSource = customerMobile;
   RadioButtonList1.DataTextField = "PhoneNumber";
   RadioButtonList1.DataValueField = "PhoneNumber";
   RadioButtonList1.DataBind();
}