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

DropDownList中使用Items 集合分别邦定了A、B、C几项. 请教以下问题?谢~
DropDownList中使用Items   集合分别邦定了A、B、C几项.     然后再拖一个Button出来.

当选择A时   点Button查询把数据库里面的资料查询到DataGrid上.   当选择B时点击Button把B里面的资料取到DataGrid上.

主要是当我选择A时,Button怎么知道我选择的是A   ?     这里是要怎么做判断.     谢谢!



------解决方案--------------------
DropDownList.SelectValue
------解决方案--------------------
string strValue = DropDownList1.SelectValue
------解决方案--------------------
strSQL = "select * from 表 where 字段= ' "+ strValue+ " ' ";
------解决方案--------------------
protected void Button1_Click(object sender, EventArgs e)
{
string chs;
chs=DropDownList1.SelectedItem.ToString(); //ddl的内容
//chs = DropDownList1.SelectedValue.ToString();//ddl的值
}

------解决方案--------------------
private void DDLBut_Click(object sender, System.EventArgs e)
{

if(DDList.SelectedValue== "A ")
{
select * from A
绑定

}
if(DDList.SelectedValue== "B ")
{
select * from B
绑定
}

}
------解决方案--------------------
private void DDLBut_Click(object sender, System.EventArgs e)
{

string chsValue;
string chsText;
chsValue=DDList.SelectedItem.Value.ToString();//DropDownList的Value
chsText=DDList.SelectedItem.Text.ToString();//DropDownList的Text
//。。。爱查什么查什么去吧.
}
------解决方案--------------------
首先确定你的 DDL 绑定 的是什么
<asp:dropdownlist id= "ddl " runat= "server " datatextfield = "Name " datavaluefield= "ID "> </asp:dropdownlist>

id 列是 SelectValue Name列是SelectText
再试试
------解决方案--------------------
button1_click(^)
{
string strCondition = ddl.selectedvalue;
if(strCondition == "A ")
{
...查询a
}
else if(strCondition == "B ")
{
...查询b
}
...
}