Hi, I have a similar question. Here is my code. Please let me know what needs to be corrected so multiple dropdown lists can be used together (in any combination) or individually. For now they all have to be selected in order for filtering to work. Thanks
Surname Search:
Given Names Search:
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT * FROM dbo.newMembersAll WHERE dbo.newMembersAll.Worksite=@Worksite AND dbo.newMembersAll.Chapter=@Chapter AND dbo.newMembersAll.BUName=@BUName AND dbo.newMembersAll.CommonName=@CommonName AND dbo.newMembersAll.Occupation=@Occupation ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames"
Runat="server"
OnSelecting="srcMembers_Selecting">
Occupation
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT DISTINCT Name AS Occupation FROM Occupations ORDER BY Name"
Runat="server" />
Barg.Unit
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT DISTINCT BUName FROM Contracts WHERE ContractID '00' ORDER BY BUName"
Runat="server" />
Worksite
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT DISTINCT Name AS Worksite FROM Worksites ORDER BY Name"
Runat="server" />
Employer
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT DISTINCT CommonName FROM Employers ORDER BY CommonName"
Runat="server" />
Chapter
"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT DISTINCT Name AS Chapter FROM Chapters WHERE ChapterID 170 ORDER BY Name"
Runat="server" />
Region
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlOccupation.DataSource = srcOccupationCategories.Select(DataSourceSelectArguments.Empty);
ddlOccupation.DataBind();
ddlOccupation.Items.Insert(0, "(All Occupations)");
ddlOccupation.SelectedIndex = 0;
ddlBU.DataSource = srcBUCategories.Select(DataSourceSelectArguments.Empty);
ddlBU.DataBind();
ddlBU.Items.Insert(0, "(All Bargaining Units)");
ddlBU.SelectedIndex = 0;
ddlWorksite.DataSource = srcWorksiteCategories.Select(DataSourceSelectArguments.Empty);
ddlWorksite.DataBind();
ddlWorksite.Items.Insert(0, "(All Worksites)");
ddlWorksite.SelectedIndex = 0;
ddlEmployer.DataSource = srcEmployerCategories.Select(DataSourceSelectArguments.Empty);
ddlEmployer.DataBind();
ddlEmployer.Items.Insert(0, "(All Employers)");
ddlEmployer.SelectedIndex = 0;
ddlChapter.DataSource = srcChapterCategories.Select(DataSourceSelectArguments.Empty);
ddlChapter.DataBind();
ddlChapter.Items.Insert(0, "(All Chapters)");
ddlChapter.SelectedIndex = 0;
}
}
protected void srcMembers_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
if ((string)e.Command.Parameters["@Occupation"].Value == "(All Occupations)")
{
e.Command.CommandText = "SELECT * FROM dbo.newMembersAll ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames";
}
if ((string)e.Command.Parameters["@Worksite"].Value == "(All Worksites)")
{
e.Command.CommandText = "SELECT * FROM dbo.newMembersAll ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames";
}
if ((string)e.Command.Parameters["@Chapter"].Value == "(All Chapters)")
{
e.Command.CommandText = "SELECT * FROM dbo.newMembersAll ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames";
}
if ((string)e.Command.Parameters["@CommonName"].Value == "(All Employers)")
{
e.Command.CommandText = "SELECT * FROM dbo.newMembersAll ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames";
}
if ((string)e.Command.Parameters["@BUName"].Value == "(All Bargaining Units)")
{
e.Command.CommandText = "SELECT * FROM dbo.newMembersAll ORDER BY dbo.newMembersAll.Surname, dbo.newMembersAll.GivenNames";
}