我想在datagrid绑定的同时把数据也绑定到dropdownlist中去,可绑定不起
我是添加的一个模板列,模板中加的dropdownlist控件
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList list = (DropDownList)e.Item.FindControl("List_yt");
string sql = "Select mean,code from code_table where code like '011%' and len(code)=6";
ds = conn.ExecuteQuery(sql);
Hashtable ht = new Hashtable();
for (int i = 0; i < 2; i++)
{
ht.Add(ds.Tables[0].Rows[i]["mean"], ds.Tables[0].Rows[i]["code"]);
}
list.DataSource = ht;
list.DataTextField = "key";
list.DataValueField = "value";
list.DataBind();
}
大家帮我看看代码吧,今天下午还必须做完哦,帮帮我。
我是添加的一个模板列,模板中加的dropdownlist控件
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList list = (DropDownList)e.Item.FindControl("List_yt");
string sql = "Select mean,code from code_table where code like '011%' and len(code)=6";
ds = conn.ExecuteQuery(sql);
Hashtable ht = new Hashtable();
for (int i = 0; i < 2; i++)
{
ht.Add(ds.Tables[0].Rows[i]["mean"], ds.Tables[0].Rows[i]["code"]);
}
list.DataSource = ht;
list.DataTextField = "key";
list.DataValueField = "value";
list.DataBind();
}
大家帮我看看代码吧,今天下午还必须做完哦,帮帮我。
{
DropDownList list = (DropDownList)e.Item.FindControl("List_yt");
string sql = "Select mean,code from code_table where code like '011%' and len(code)=6";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
list.DataSource = ds;
list.DataTextField = "mean";
list.DataValueField = "code";
list.DataBind();
}
Object reference not set to an instance of an object
不行呀list.DataSource = ds;就这里呀。
帮帮忙了