【发布时间】:2020-07-06 05:57:29
【问题描述】:
我做了一个搜索按钮,它将显示从 sql 到 gridview 的数据,搜索按钮与 DropDownList 连接,其中包含两个值(是)和(否),所以如果用户选择(是)它应该获取数据所在的位置value 等于 (yes) 与 (no) 相同。这对我来说很好,我确实分开吃一个,但如果我同时搜索两个 DropDownList,它会给我第一个 DropDownList 正确但第二个错误,例如如果 DropDownList1 = "yes" 显示(是)值,如果 DropDownList2 = "no" 显示 (no) 值,它会返回 (yes) 他们两个,
这是我的代码:
if (DropDownList_laptop.SelectedValue == "1")
{
// ... code here
SqlDataSource1.SelectCommand = "SELECT * FROM emp_table where inv_lap = 'yes'";
}
else if (DropDownList_laptop.SelectedValue == "2")
{
// ... code here
SqlDataSource1.SelectCommand = "SELECT * FROM emp_table where inv_lap = 'no'";
}
else if (DropDownList_pc.SelectedValue == "1")
{
// ... code here
SqlDataSource1.SelectCommand = "SELECT * FROM emp_table where inv_pc = 'yes'";
}
else if (DropDownList_pc.SelectedValue == "2")
{
// ... code here
SqlDataSource1.SelectCommand = "SELECT * FROM emp_table where inv_pc = 'no'";
}
下拉代码:
<asp:DropDownList ID="DropDownList_laptop" runat="server" Height="29px" Width="70px">
<asp:listitem text="" value="0"></asp:listitem>
<asp:listitem text="yes" value="1"></asp:listitem>
<asp:listitem text="no" value="2"></asp:listitem>
</asp:DropDownList>
【问题讨论】:
-
else if (DropDownList_pc.SelectedValue == "1") 在这一行为什么有一个“else if”而不是only if?
-
SqlDataSource1和DropDownList1或DropDownList2有什么关系?