C# 未使用单选按钮将对象引用设置为对象的实例

C# 未使用单选按钮将对象引用设置为对象的实例,c#,asp.net,radio-button,C#,Asp.net,Radio Button,我得到这个错误,我认为它来自一个单选按钮。有没有办法解决这个问题 以下是aspx: <asp:RadioButton ID="radL" runat="server" GroupName="Gender" Checked="false" Text="L" AutoPostBack="true" /> <asp:RadioButton ID="radP" runat="server" GroupName="Gender" Checked="false" Text="P"

我得到这个错误,我认为它来自一个单选按钮。有没有办法解决这个问题

以下是aspx:

  <asp:RadioButton ID="radL" runat="server" GroupName="Gender" Checked="false" Text="L" AutoPostBack="true" />
   <asp:RadioButton ID="radP" runat="server" GroupName="Gender" Checked="false" Text="P" AutoPostBack="true" />

在强制转换FindControl语句的结果之前,应该检查null

例如这条线

RadioButton JAN = (RadioButton)editedItem.FindControl("JAN");
应改为

RadioButton JAN;
if(editedItem.FindControl("JAN") != null)
{
   RadioButton JAN = (RadioButton)editedItem.FindControl("JAN");
}

如果您将此作为例外,请发布堆栈跟踪。这将有助于隔离导致问题的代码行。为什么你不能调试并找出它到底在哪一行上爆炸?你有Id为JAN的单选按钮吗?如果我逐行检查代码,所有项目都保存该值,JAN单选按钮保存选中的radL或radP单选按钮的值。在设计器零件中没有任何单选按钮JAN。这就是为什么会出现这个错误。让它成为唯一的单选按钮;。然后给它赋值。
RadioButton JAN;
if(editedItem.FindControl("JAN") != null)
{
   RadioButton JAN = (RadioButton)editedItem.FindControl("JAN");
}