带有ok按钮的下拉列表将触发搜索文本框和搜索按钮在web浏览器中可见
本文关键字:按钮 搜索 web 浏览器 文本 下拉列表 带有 ok | 更新日期: 2023-09-27 18:00:02
这里我有一个DropDownList和按钮ok,当点击它时,它将启用其他搜索文本框和搜索按钮的可见性。此外,这取决于我选择DropDownList项目的内容。比方说,在我的下拉列表中,我有ProductName和ProductCode。我现在选择ProductName此地址列表旁边是按钮ok。当我单击按钮ok时,标签、文本框名称和按钮SearchName等控件将显示在它的下面。我怎样才能做到这一点?
<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,但如果您在同一页面中有其他控件(如FileUpload控件),则您也需要ScriptManager,而这些控件在存在ScriptManager的情况下无法正常工作。
或者,您可以使用相同的TextBox来搜索所有字段,方法是检测DropDownList中选择的值,并根据该值,搜索算法会相应更改。
所以我刚刚将您的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;