protected void get_city()
    {   City ci = new City(); 
        DataSet ds1 = ci.show_city();
        foreach (GridViewRow gv in this.GridView1.Rows)
        {
        DropDownList dr = (DropDownList)gv.FindControl("C_name");    
        dr.DataSource = ds1.Tables[0];//未将对象引用设置到对象的实例        
        dr.DataTextField = "C_name";
        dr.DataValueField = "C_id";
        dr.DataBind();
        
       }
        ds1.Dispose();
    }
 未将对象引用设置到对象的实例!!! 这是怎么回事啊?没找到控件吗????
 在GRIDVIEW中有个Dropdownlist ID为C_name

解决方案 »

  1.   

      DataSet ds1 = ci.show_city(); 
    ci.show_city();  有没有取出东西,返回null了吧
      

  2.   

    City ci = new City(); 
    是什么意思
      

  3.   

    DataSet ds1 = ci.show_city();这句话返回的不是空??
      

  4.   

    楼主,如果你要让你妹妹的老公借你500块钱你要怎么去思维这件事情呢?首先你是不是要看你有没有妹妹阿,如果你有妹妹你还要向她结婚没,如果你有妹妹了她也结婚了你才能考虑让她老公借你钱的可能性是吧?如果前提都不存在就考虑是否能借到钱显然逻辑上就是错误的。那么同样,编译器看见类似于ds1.Tables[0]这样的东西的时候首先会看ds1是否存在,如果不存在或者为Null那就不谈后面的.Table了,所以当你写.这个运算符的时候心里加个小心,不确定的时候一定要作个验证
    if(ds1 != null)
    {
      。
    }
      

  5.   

    City ci = new City(); 
    DataSet ds1 = ci.show_city(); 
    看起来问题在这两句
    看看你的city的构造函数,是不是有别的重载,因为一个完全没有参数的构造函数很难想象会构造一个独特的实例出来,这样他的.showCity方法很有可能返回null
      

  6.   

     protected void gets()
        {
            City ci = new City();
            DataSet ds = ci.show_city();
            this.DropDownList1.DataSource = ds.Tables[0];
            this.DropDownList1.DataTextField = "C_name";
            this.DropDownList1.DataValueField = "C_id";
            this.DropDownList1.DataBind();
            ds.Dispose();
        }
        Points po = new Points();
        protected void get_city()
        {   City ci = new City(); 
            DataSet ds1 = ci.show_city();
            if (ds1 != null)
            {
              foreach (GridViewRow gv in this.GridView1.Rows)
              {
                DropDownList dr = (DropDownList)gv.FindControl("C_name");
                dr.DataSource = ds1.Tables[0];
                dr.DataTextField = "C_name";
                dr.DataValueField = "C_id";
                dr.DataBind();
              }
             }
             else
             {
                Response .Write("ok");
             }
          ds1.Dispose();
        }
          上面有个GETS方法,同样是获取城市的,用的是同一个存储过程,运行 的时候城市都列出来了,而下面的get_city()
          在我一点击gridview编辑时就出现了:未将对象引用设置到对象的实例
           加了IF(DS1!=NULL)还是一样
      

  7.   

    调试一下噻!看是那里对象是null在从那里入手