读书人

怎么获取下拉列表中的选项

发布时间: 2012-03-09 21:42:52 作者: rapoo

如何获取下拉列表中的选项

怎么在点击查询后让程序获取到这两个下拉列表中的选项

[解决办法]
用循环读取combobox.Items的所有元素就可以,
[解决办法]
在点击按钮的事件代码中添加如下两行代码即可。

C# code
public void btnQuery_Click(object sender,EventArgs e){      ...       string s1 = this.DropDownList1.SelectedItem.Text.Trim();       string s2 = this.DropDownList2.SelectedItem.Text.Trim();       ...}
[解决办法]
WinForm的ComboBox啊,本来还以为是DropDownList呢

C# code
private void button1_Click(object sender, EventArgs e){  string s1 = this.comboBox1.SelectedValue; // this.comboBox1.SelectedText;  string s2 = this.comboBox2.SelectedValue; //this.comboBox2.SelectedText;}
[解决办法]
string s1 = this.comboBox1.SelectedValue.ToString();
string s2 = this.comboBox2.SelectedText.Trim();

读书人网 >C#

热点推荐