当我在Gridview中分配时,单选按钮列表值显示为null

时间:2017-08-05 07:18:04

标签: c# asp.net

错误显示

  

对象引用未设置为对象的实例。

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";
    }

0 个答案:

没有答案