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
{ 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
ci.show_city(); 有没有取出东西,返回null了吧
是什么意思
if(ds1 != null)
{
。
}
DataSet ds1 = ci.show_city();
看起来问题在这两句
看看你的city的构造函数,是不是有别的重载,因为一个完全没有参数的构造函数很难想象会构造一个独特的实例出来,这样他的.showCity方法很有可能返回null
{
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)还是一样