I hvae a dropdownlist tied to a SQLDataSource that returns a list of Categories. Since this is used as part of a search function, how do I add a "Select All" category and ensure that such a selection queries all categories?
Thanks much!!
I hvae a dropdownlist tied to a SQLDataSource that returns a list of Categories. Since this is used as part of a search function, how do I add a "Select All" category and ensure that such a selection queries all categories?
Thanks much!!
Never Use (AppendDataBoundItems="true")!
<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";
}
}
}
I sometimes use sql for this:
select value, description from reference_table
union
select -1, 'Select all'
Order by 2
There is also the way where you add the item in the markup, then set the AppendDataBoundItems="true"