Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
whenever i am excuting the below code am getting the error at the rbYes.Checked==true as nullreferenceexception was unhandled by user code asp.net
C#
protected void rgDesignation_ItemCommand(object source, GridCommandEventArgs e)
  {
      if (e.CommandName == "InitInsert")
      {
          for (int k = 0; k < rgDesignation.Items.Count; k++)
          {
              if (rgDesignation.Items[k].Edit)
              {
                  e.Canceled = true;
                  return;
              }
          }
      }
      if (e.CommandName == "Edit")
      {
          if (rgDesignation.MasterTableView.IsItemInserted)
          {
              e.Canceled = true;
              return;
          }
          GridEditableItem editItem = (GridEditableItem)e.Item;
          RadTextBox txDesignation = (RadTextBox)editItem.FindControl("txDesignation");

          RadioButton rbYes = (RadioButton)editItem.FindControl("rbYes");
          RadioButton rbNo = (RadioButton)editItem.FindControl("rbNo");
          RadioButton rbUser = (RadioButton)editItem.FindControl("rbUser");
          int DesgID = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DesgID"];
          DataView dv;
          DataSet ds = new DataSet();
          ds = DataAccessLayer.BindDataQuery("select Estatus1 from tblDesignations where DesgID='" + DesgID + "'");
          dv = ds.Tables[0].DefaultView;
          int Name;
          // args.IsValid = true;

          //foreach (DataRowView datarow in dv)
          //{
              int a = 1, b = 2, c = 3;
              Name = Convert.ToInt32(ds.Tables[0].Rows[0]["Estatus1"]);
              if (Name == a)
              {
                  rbYes.Checked = true;
                  rbNo.Checked = false;
                  rbUser.Checked = false;
              }
              else if (Name==b)
              {
                  rbNo.Checked = true;
                  rbYes.Checked = false;
                  rbUser.Checked = false;
              }
              else
              {
                  rbUser.Checked = true;
                  rbNo.Checked = false;
                  rbYes.Checked = false;
              }

          //}
      }
  }
Posted
Updated 27-Aug-12 20:51pm
v2
Comments
Arif Ansari Code 14-Nov-13 7:24am    
Did you set Brack Point on your Code where you get error?

This Exception is showing because the control is unable to detect.
Means:unable to render the control.

Check the name "rbYes" is correct or not.

rest looks ok.
 
Share this answer
 
The FindControl is probably not finding the name you specified at the line :
C#
RadioButton rbYes = editItem.FindControl("rbYes");

Check the name "rbYes" is correct.
 
Share this answer
 
Basically, your code failed to find a control called "rbYes".
C#
RadioButton rbYes = (RadioButton)editItem.FindControl("rbYes");
Check that your editItem actually contains this, or that you have spelled it correctly.
 
Share this answer
 
I faced the similar problem, issue here is RadTextBox txDesignation = (RadTextBox)editItem.FindControl("txDesignation");
has to be checked for Null. If any one has any idea, pl. help
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900