如何获取下拉列表中的选项
怎么在点击查询后让程序获取到这两个下拉列表中的选项
[解决办法]
用循环读取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();