首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-03-09 
如何获取下拉列表中的选项怎么在点击查询后让程序获取到这两个下拉列表中的选项[解决办法]用循环读取combo

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

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

[解决办法]
用循环读取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();

热点排行