【发布时间】:2014-09-05 11:16:53
【问题描述】:
我有一个单选按钮列表,通过这种方法将其与数据绑定:
DataTable dt1 = BeeStatus.GetAllBeeStatus();
radio1.DataSource = dt1;
radio1.DataTextField = "beeStatus";
radio1.DataValueField = "beestatusID";
radio1.DataBind();
当我尝试获取所选项目的值时,通过编写:
int st = Convert.ToInt32( radio1.SelectedItem.value);
它给出了这个错误:
[“/”应用程序中的服务器错误。
对象引用未设置为对象的实例。
Description: An unhandled exception occurred during the execution of the current
web request.
Please review the stack trace for more information about the error and where
it originated in the code. ]
有什么帮助吗?
异常详情: System.NullReferenceException:对象引用未设置为对象的实例。
【问题讨论】:
-
radio1.SelectedItem.value的某些部分为空,在调试器中检查它,例如如果没有选择任何值,那么 radio1.SelectedItem 将为空。在尝试转换为 int 之前,您需要进行一次空值检查。 -
我已经检查过了,同样的错误。
标签: c# asp.net radiobuttonlist