dropdownlist绑定数据库?
protectedvoidDropDownList1_SelectedIndexChanged(objectsender,EventArgse){SqlConnectio...
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.;database=yangguang;uid=zxh;pwd=123456");
con.Open();
string sql = "select kindid,kindname from goodskind ";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "goodskind");
con.Close();
DropDownList1.DataSource = ds.Tables["goodskind"].DefaultView;
DropDownList1.DataTextField = "kindname"; //dropdownlist的Text的字段
DropDownList1.DataValueField = "kindid";//dropdownlist的Value的字段
DropDownList1.DataBind();
}
不能绑定!为什么???? 展开
{
SqlConnection con = new SqlConnection("server=.;database=yangguang;uid=zxh;pwd=123456");
con.Open();
string sql = "select kindid,kindname from goodskind ";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "goodskind");
con.Close();
DropDownList1.DataSource = ds.Tables["goodskind"].DefaultView;
DropDownList1.DataTextField = "kindname"; //dropdownlist的Text的字段
DropDownList1.DataValueField = "kindid";//dropdownlist的Value的字段
DropDownList1.DataBind();
}
不能绑定!为什么???? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询