2011-06-22 22 views
0

ここで私はDropDownListとButton okをクリックして、他の検索テキストボックスと検索ボタンの表示を有効にします。また、これは私がDropDownList項目を選択することに依存します。私のDropDownListでは、ProductNameとProductCode.IがProductNameを選択しています。このddlistの隣にボタンがあります。ボタンokをクリックすると、labelなどのコントロール、textboxName、buttonSearchNameがその下に表示されます。 どうすればこのことができますか?OKボタン付きドロップダウンリストは、検索テキストボックスと検索ボタンをウェブブラウザで表示するようにします。

<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 /> 

答えて

0

Falseに更新パネルとセット可視性を追加するために、しかし、あなたはまたのScriptManagerを必要とし、あなたが他のコントロールを持っている場合はそれを行うための一つの方法は、(私の前に答えとして)である、あなたの質問に答えるためにScriptManagerが存在すると正常に動作しない同じページ(FileUploadコントロールなど)。

ドロップダウンリストで選択された値を検出し、その値に基づいて検索アルゴリズムを変更するメソッドを実装することで、同じ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; 

    } 
} 
+0

うん、それはこのようなはずです。正しく働いている限り、これを行うには十分です。ありがとうございます。これに答えるためにあなたを投票するにはどうすればいいのですか? –

+0

私の答えの横にある^ 0の下にブランクのチェックマークがあります。その隣にマウスを置くと、(この回答を受け入れる) – Ahmad

0

これを行う方法の多くが、あなただけの最も簡単な方法を開始してからパネルにあなたのコントロールを配置し、あなたの「btnOK_Click」イベントでの視認性を変更することです。

例:

<asp:Panel id="searchPanel" runat="server" visible="false"> 
    your controls here.... 
</asp:Panel> 

はあなたのイベントには、次の構文を使用して、これが見えるようにします。

searchPanel.Visible = True; 
+0

どのように見えるかの例です。 Nice!しかし、ProductCodeなどの他の項目を選択すると、ddllistを使用する方法は? panelProductNameが消滅すべきか?または、同じパネル(私のパネルはpanel1)で、productCodeに関連付けられたコントロールだけを表示するようにトリガする? –

+0

ドロップダウンリストの各オプションは異なるコントロールセットを持つでしょうか?従来のASP.NETポストバックを使用する最も簡単な方法は、/オプションごとに1パネルを作成することです。次に、選択した項目のドロップダウンリストに基づいて、表示/非表示のパネルを指定できます。また、呼び出すことができるヘルパー関数を作成して、すべてのパネルを非表示にし、表示したいパネルのみを表示することもできます。 "ShowPanel(productCodePanel)"のように呼び出すと、すべてのパネルが非表示になり、 "productCodePanel"だけが表示されます。 – Zachary

関連する問題