日期:2014-05-18  浏览次数:20780 次

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

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

------解决方案--------------------
用循环读取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();