Here I have a DropDownList and Button ok that when clicked, it will enable visibility of other search textbox and search button. Also, this depend on what I select DropDownList item. Say, in my DropDownList, I have ProductName and ProductCode.I now select ProductName Next to this ddlist is button ok. When I click button ok, control such as label, textboxName and buttonSearchName will appear below of it. How can I accomplish this?
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>ProductName</asp:ListItem>
<asp:ListItem>ProductCode</asp:ListItem>
<asp:ListItem>Category</asp:ListItem>
开发者_JAVA技巧<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 />
To answer your question, one way to do it is (as answered before me) to add an update panel and set visibility to False, but then you would also require a ScriptManager and if you have other controls in the same page (such as a FileUpload control) that will not work properly with the presence of a ScriptManager.
You could alternatively use the same TextBox to search for all of the fields, by implementing a method that detects the value selected in your DropDownList and based on that value, the search algorithm changes accordingly.
So I just renamed your txtSearchProduct
to just txtSearch
and I added a universal method to search all criteria named 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 />
and here is an example of what would the btnSearch_Click
look like
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;
}
}
Lots of ways to do this, but since your just starting the easiest thing to do would be to put your controls in a panel and change the visibility in your "btnOK_Click" event.
Example:
<asp:Panel id="searchPanel" runat="server" visible="false">
your controls here....
</asp:Panel>
To make this visible, in your event use the following syntax.
searchPanel.Visible = True;
精彩评论