我在webForm中添加了一个RadioButtonList控件,带有5个item,运行的时候,如果你选择了一个的话,运行正常,可是,如果一个都没有选择,则出现error。
我用button做的提交。
错误如下
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 58: else {RadioLabel.Text=MyJobRb.Text;}
行 59: //如果选择了mysturb,则RadioLabel的文本为MyJobRb.Text;
行 60: if (MyRBList.SelectedItem.Selected==true)
行 61: { ListLabel.Text=MyRBList.SelectedItem.Text;}
行 62: else ListLabel.Text="111";
源文件: c:\inetpub\wwwroot\aspx\singmutibuttons\webform1.aspx.cs 行: 60 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
SingMutiButtons.WebForm1.SureBtn_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\aspx\singmutibuttons\webform1.aspx.cs:60
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
我用button做的提交。
错误如下
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 58: else {RadioLabel.Text=MyJobRb.Text;}
行 59: //如果选择了mysturb,则RadioLabel的文本为MyJobRb.Text;
行 60: if (MyRBList.SelectedItem.Selected==true)
行 61: { ListLabel.Text=MyRBList.SelectedItem.Text;}
行 62: else ListLabel.Text="111";
源文件: c:\inetpub\wwwroot\aspx\singmutibuttons\webform1.aspx.cs 行: 60 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
SingMutiButtons.WebForm1.SureBtn_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\aspx\singmutibuttons\webform1.aspx.cs:60
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
解决方案 »
- 从字符串 到类型 Double 的转换无效
- 怎么做网页游戏平台中记录用户“以玩过的游戏”?
- flex 动态加载imageMap
- DataNavigateUrlFields="title" DataNavigateUrlFormatString="article_detail.aspx?articleTitle=Server.UrlEncode({0})"
- 无法从int隐转换到System.Data.SqlClient....
- TextBox 如何与DataSet里一个字段榜定阿?谢谢了!
- 怎样在火狐下让图片变成灰色??
- 【紧急】求问:关于IE浏览器操作缓存的JS数据,显示不正常,其他浏览器则正常
- 我因为这个问题都要吐血了(在线的,马上结!):javascrip怎么调用.cs中的方法!!
- 哥哥,推荐本asp.net的书吧,我在书店转晕了
- 我做一个修改用户资料的页面,无法把修改后的信息写进数据库,其实数据是写进去了,但控件记住的是原来的状态,而不是当前的状态,望高人
- 数据库中字段为tinyint型,我保存时用int型,报错!(救我!)
===>
if (MyRBList.SelectedIndex>=0)
不过大哥,我将MyRBList的任意一个item的selected 设置为true重新运行也是可以的。
这2种方法有何区别呢?MyRBList.SelectedIndex>=0中>=0怎么解?