错误显示
对象引用未设置为对象的实例。
在rdb5.SelectedValue = "1"
并开始阻止。数据正确并进入循环内部,但错误显示在rdb5.SelectedValue = "1"
。
RadioButtonList rdb5 = (RadioButtonList)e.Row.FindControl("rdb5");
RadioButtonList rdb6 = (RadioButtonList)e.Row.FindControl("rdb6");
RadioButtonList rdb7 = (RadioButtonList)e.Row.FindControl("rdb7");
using (SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConStr1"]))
{
string sql = "select * from RateSchedule ";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
string s = ds.Tables[0].Rows[0]["RegularLabor"].ToString().Trim();
if (ds.Tables[0].Rows[0]["TaskType"].ToString() == "Default")
{
}
if (ds.Tables[0].Rows[0]["RegularLabor"].ToString().Trim() == "True")
{
rdb5.SelectedValue = "1";
//Here it is showing error "Object reference not set to an instance of an object."
}
else
{
rdb5.SelectedValue = "2";
}