本文介绍了带有下拉框的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
SqlCommand cmd = new SqlCommand("select ID from login order by ID",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.Items.Insert(0, "--Select One--");
DropDownList1.DataTextField = "id";
DropDownList1.DataBind();
在这种情况下,我无法将DropDown值设置为0,即-选择一个-"
请检查以下快照...
http://s7.postimage.org/fxks94fmj/drop.jpg [ ^ ]
In this, I am not able set the DropDown value to 0 i.e.,"--Select One--"
Please check following snapshot...
http://s7.postimage.org/fxks94fmj/drop.jpg[^]
推荐答案
SqlCommand cmd = new SqlCommand("select ID from login order by ID",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "id";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--Select One--", ""));
尝试使用它,让我知道...
谢谢...
Try using this and let me know...
Thanks...
SqlCommand cmd = new SqlCommand("select ID from login order by ID", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.AppendDataBoundItems = true;
DropDownList1.Items.Insert(0, new ListItem("--Select One--", "0"));
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "id";
DropDownList1.DataBind();
这篇关于带有下拉框的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!