如何在Windows应用程序的组合框中默认显示-Select- [英] How to display -Select- by default in combobox in windows application
本文介绍了如何在Windows应用程序的组合框中默认显示-Select-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有2个组合框.我要在来自数据库的page_load事件中的组合框中显示数据.我想在组合框中以默认值显示"-Select-".然后在组合框中显示数据库值.
i have 2 combo box in my application. i am display data in combo box in page_load event from database.i want display "-Select-" by default value in combo box. and after that display database value in combo box.
推荐答案
使用此
SqlCommand comm = new SqlCommand("select * from EmpDetail");
SqlDataAdapter adap = new SqlDataAdapter(comm);
comm.Connection = conn;
DataSet ds = new DataSet();
adap.Fill(ds);
comboBox1.Text = "-select-";
foreach(DataRow dr1 in ds.Tables[0].Rows)
{
comboBox1.Items.Add(dr1["EmpName"].ToString());
}
希望它能在绑定CombooBox之后醒来
Hope this will wok
.
if(ComboBox1.Items.Count>0)
{
ComboBox1.Items.Insert(0, "Select Item");
ComboBox1.SelectedIndex = 0;
}
从数据库绑定组合框后,您需要根据需要在第0个索引处添加一个额外的项目.
试试这个:
After binding the combobox from database you need to add one extra item at 0th Index as you required.
Try this:
ComboBox1.Items.Insert(0, new ComboBoxItem("-Select-", string.Empty));
--Amit
--Amit
这篇关于如何在Windows应用程序的组合框中默认显示-Select-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文