显示从数据库中获取的组合框中的选定值(Showing a selected value in combobox fetched from database)
private void Form1_Load_1(object sender, EventArgs e) { string Sql = "select status from lk_tb_project_status"; OleDbConnection con = new OleDbConnection(constr); OleDbCommand com = new OleDbCommand(Sql, con); con.Open(); OleDbDataReader DR = com.ExecuteReader(); while (DR.Read()) { comboBox1.Items.Add(DR[0]); } }
我从数据库中获取值并显示在combobox(下拉列表)中。 数据库中有两个值已售出和打开。 我想要的是在页面加载时更改所选项目。 谁能帮我这个?
private void Form1_Load_1(object sender, EventArgs e) { string Sql = "select status from lk_tb_project_status"; OleDbConnection con = new OleDbConnection(constr); OleDbCommand com = new OleDbCommand(Sql, con); con.Open(); OleDbDataReader DR = com.ExecuteReader(); while (DR.Read()) { comboBox1.Items.Add(DR[0]); } }
I am fetching values from database and displaying in combobox(dropdownlist). There are two values in database that is sold and open. What I want is to change selected item on page load. Can anyone help me with this?
原文:https://stackoverflow.com/questions/22040152
更新时间:2022-11-16 15:11
最满意答案
已更新答案
我注意到很多人都在使用这个答案,所以我决定稍微更新一下。 如果您想查看原始答案,请查看下面的内容。 新的答案演示了如何将一些样式添加到列表中。
ul > li { display: inline-block; /* You can also add some margins here to make it look prettier */ zoom:1; *display:inline; /* this fix is needed for IE7- */ }
<ul> <li> <a href="#">some item</a> </li> <li> <a href="#">another item</a> </li> </ul>
Updated Answer
I've noticed a lot of people are using this answer so I decided to update it a little bit. If you want to see the original answer, check below. The new answer demonstrates how you can add some style to your list.
ul > li { display: inline-block; /* You can also add some margins here to make it look prettier */ zoom:1; *display:inline; /* this fix is needed for IE7- */ }
<ul> <li> <a href="#">some item</a> </li> <li> <a href="#">another item</a> </li> </ul>
相关问答
更多-
CSS水平列表项目(Horizontal list items)[2023-09-20]
已更新答案 我注意到很多人都在使用这个答案,所以我决定稍微更新一下。 如果您想查看原始答案,请查看下面的内容。 新的答案演示了如何将一些样式添加到列表中。 ul > li { display: inline-block; /* You can also add some margins here to make it look prettier */ zoom:1; *display:inline; /* this fix is needed for IE7 ...