2011-12-05 10 views
1

私はドロップダウンリストをカテゴリのリストを返すSQLDataSourceに関連付けています。これは検索機能の一部として使用されるため、「すべて選択」カテゴリを追加して、そのような選択がすべてのカテゴリを照会するようにするにはどうすればよいですか?SQLDataSourceに関連付けられたドロップダウンリストに「すべて選択」項目を追加するにはどうすればよいですか?

ありがとうございます!

答えて

0

私は時々、このためにSQLを使用します。

select value, description from reference_table 
union 
select -1, 'Select all' 
Order by 2 

はまた、あなたがマークアップで項目を追加方法があり、その後、AppendDataBoundItems = "true" にも

を、設定see this similar question and answer

0

絶対に使用しないでください(AppendDataBoundItems = "true")! (AppendDataBoundItemsを= "真")を使用したことがないのはなぜ

<asp:DropDownList ID="drpdwnmodel" DataSourceID="Model_Grid" DataTextField="INI" DataValueField="INI" OnSelectedIndexChanged="drprep_SelectedIndexChanged" OnDataBound="DataBoundbyTest_click" AutoPostBack="true" runat="server"> 
 
          <asp:ListItem Value="All" Text="All"></asp:ListItem> 
 
         </asp:DropDownList> 
 

 

 
    <asp:SqlDataSource ID="Model_Grid" runat="server" 
 
       ConnectionString="<%$ ConnectionStrings:Testconnectionstring%>" 
 
       SelectCommand="SELECT DISTINCT INI FROM TestTable where [Column] LIKE '%' + @valuename+ '%' ORDER BY INI ASC"> 
 
       <SelectParameters> 
 
        <asp:ControlParameter ControlID="drpdwnmodel" Name="valuename" 
 
         PropertyName="SelectedValue" Type="String" /> 
 
       </SelectParameters> 
 
      </asp:SqlDataSource> 
 

 
protected void DataBoundbyTest_click(object sender, EventArgs e) 
 
    { 
 
     drpdwnmodel.Items.Add("All"); 
 
     drpdwnmodel.Items.Insert(0, new ListItem("- Select -", "0")); 
 
    } 
 

 

 
protected void drprep_SelectedIndexChanged(object sender, EventArgs e) 
 
    { 
 
     if (drpdwnmodel.SelectedValue.Equals("0")) 
 
     { 
 
      GridView1.DataSourceID = "Test_Grid"; 
 
     } 
 
     else { 
 
      if (drpdwnmodel.SelectedValue.Equals("All")) 
 
      { 
 
       GridView1.DataSourceID = "Test_Grid"; 
 
      } 
 
      else 
 
      { 
 
       GridView1.DataSourceID = "SqlDataSource1"; 
 
      } 
 
     } 
 
     
 
    }

+0

? – Peanut

+0

ドロップダウンリストにデータを重複させるため –

関連する問題