如何解决带有ok按钮的下拉列表将触发搜索文本框和搜索按钮在Web浏览器中可见
|| 在这里,我有一个DropDownList和Button ok,当单击它们时,它将启用其他搜索文本框和搜索按钮的可见性。另外,这取决于我选择DropDownList项目的方式。说,在我的DropDownList中,我有ProductName和ProductCode。我现在选择ProductName在此ddlist旁边的是OK按钮。当我单击“确定”按钮时,诸如label,textboxName和buttonSearchName之类的控件将显示在其下方。 我该怎么做? <asp:DropDownList ID=\"DropDownList1\" runat=\"server\">
<asp:ListItem>ProductName</asp:ListItem>
<asp:ListItem>ProductCode</asp:ListItem>
<asp:ListItem>Category</asp:ListItem>
<asp:ListItem>SellingPrice</asp:ListItem>
<asp:ListItem>Quantity</asp:ListItem>
<asp:ListItem>BrandName</asp:ListItem>
<asp:ListItem>ReOrderQty</asp:ListItem>
<asp:ListItem>ReOrderLevel</asp:ListItem>
<asp:ListItem>Ordered</asp:ListItem>
<asp:ListItem>Allocated</asp:ListItem>
<asp:ListItem>FreeQty</asp:ListItem>
</asp:DropDownList>
<asp:Button ID=\"btnOK\" runat=\"server\" onclick=\"btnOK_Click\" Text=\"OK\" />
<br />
ProductName<asp:TextBox ID=\"txtSearchProductname\" runat=\"server\"></asp:TextBox>
<asp:Button ID=\"btnSearchProductName\" runat=\"server\" Text=\"search\"
onclick=\"btnSearchProductName_Click\" />
<br />
解决方法
要回答您的问题,一种方法是(如在我之前所回答的)添加一个更新面板并将可见性设置为False,但是这时您还需要一个ScriptManager以及同一页面中是否有其他控件(例如FileUpload控件)在存在ScriptManager的情况下将无法正常工作。
通过实现一种检测在DropDownList中选择的值并基于该值的搜索方法,您也可以使用同一TextBox搜索所有字段。
所以我只是将您的
txtSearchProduct
重命名为txtSearch
,并且添加了一种通用方法来搜索所有名为btnSearch_Click
的条件
<asp:DropDownList ID=\"DropDownList1\" runat=\"server\">
<asp:ListItem>ProductName</asp:ListItem>
<asp:ListItem>ProductCode</asp:ListItem>
<asp:ListItem>Category</asp:ListItem>
<asp:ListItem>SellingPrice</asp:ListItem>
<asp:ListItem>Quantity</asp:ListItem>
<asp:ListItem>BrandName</asp:ListItem>
<asp:ListItem>ReOrderQty</asp:ListItem>
<asp:ListItem>ReOrderLevel</asp:ListItem>
<asp:ListItem>Ordered</asp:ListItem>
<asp:ListItem>Allocated</asp:ListItem>
<asp:ListItem>FreeQty</asp:ListItem>
</asp:DropDownList>
<br />
Search: <asp:TextBox ID=\"txtSearch\" runat=\"server\">
</asp:TextBox>
<asp:Button ID=\"btnSearch\" runat=\"server\" Text=\"search\"
onclick=\"btnSearch_Click\" />
<br />
这是btnSearch_Click
的示例
protected void btnSearch_Click(object sender,EventArgs e)
{
string searchText = this.txtSearch.Text;
switch (this.DropDownList1.SelectedValue.ToString) {
case \"ProductName\":
string sql = \"select * from products where ProductName like \'%\" + searchText + \"%\'\";
// the rest of your code goes here
break;
case \"ProductCode\":
string sql = \"select * from products where ProductCode like \'%\" + searchText + \"%\'\";
// populate some other control with your productcode search here
break;
}
}
, 有很多方法可以执行此操作,但是由于您刚开始最简单的操作就是将控件放在面板中并更改\“ btnOK_Click \”事件的可见性。
例:
<asp:Panel id=\"searchPanel\" runat=\"server\" visible=\"false\">
your controls here....
</asp:Panel>
要使其可见,请使用以下语法。
searchPanel.Visible = True;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。