带有下拉框的数据集 [英] dataset with dropdown box
本文介绍了带有下拉框的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
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[^]
推荐答案
请检查答案回答-"DropDownList.SelectedIndex = -1"问题
[^ ]
在下拉列表绑定后它说要插入该值的地方...
在您的代码中,如下所示...
Please check the answer Answer to - "DropDownList.SelectedIndex = -1" problem
[^]
Where it says to insert that value after the dropdown is bound...
In your codes do like below...
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...
您应该使用AppendDataBoundItems
属性.请注意正确的代码段.
You should useAppendDataBoundItems
property. Note the correct Code snippets.
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();
这篇关于带有下拉框的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文