Hey guys I know it had been discussed so much but I still don't get it working.

What I need is to filter a gridview by a few dropdown lists and the main idea is to "continue" filtering the gridview. I mean, when I select value from ddl1, then the ddl2 is filtered according to the selected value in ddl1 and so forth

Also called cascading dropdown list but I don't want to (can not) use Ajax Control Toolkit...

Any other solutions to that? Maybe the method

protected void DropDownList2_SelectedIndexChanged(...)

can do this but I don't know how to use it.


Please help Thanks in advance.

try to use single binding data source to all the controls(combos and grid)

Do you mean to use only one datasource for all dropdown lists ?!
Otherwise I bind all the datasources in the code behind:

protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                ddlProjectID.DataSource = sqlDataSourceProjectID;
                ddlProjectID.DataBind();
                

                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect("~/ErrorPage.aspx");
                }

                ddlPad.DataSource = sqlDataSourcePad;
                ddlPad.DataBind();

                ddlStart_date.DataSource = SqlDataSourceStartDate;
                ddlStart_date.DataBind();

I tried the normal datasource line in the html code but same result...

i think you have data source with 2 tables :
table 1: dept
table 2: emp
FK: deptEmp_FK
add dataSource(DataSet,Linq,....) instance ds1
for Combo1 set data source dept table of ds1
for Combo2 set data source deptEmp_FK of ds1

No it's only one table and I'm using SQLDatasource for each dropdown list + the one for the gridview..
:?

ok you can go to the data source and create query

SELECT ID, Name, Dep FROM dbo.Emp
WHERE  Dep > @ParameterName

and press ok
set combo value member to the Dep
and in form on combo selectedIndexChanged

try
            {
                tableAdapterObj.NewQueryName(dataSetObj.Emp, new System.Nullable<int>(((int)(System.Convert.ChangeType(combobox1.selectedValue.ToString(), typeof(int))))));
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

I don't really understand your point of using combo boxes rather than a normal dropdownlist.
I have another idea... in the data sources for each dropdown list, the sql SELECT command like this:

<asp:SqlDataSource ID="sqlDataSourcePad" runat="server"  
     ConnectionString="<%$ ConnectionStrings:LocalMySqlServer %>" 
     ProviderName="<%$ ConnectionStrings:LocalMySqlServer.ProviderName %>" 
     SelectCommand="SELECT DISTINCT user_field_2330 FROM task WHERE project__proj_short_name = @project">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlProjectID" Name="project" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
asp:SqlDataSource ID="SqlDataSourceStartDate" runat="server" 
                ConnectionString="<%$ ConnectionStrings:LocalMySqlServer %>" 
                ProviderName="<%$ ConnectionStrings:LocalMySqlServer.ProviderName %>" 
                SelectCommand="SELECT DISTINCT start_date FROM task WHERE project__proj_short_name = @project AND pad_no=@pad">
     <SelectParameters>
            <asp:ControlParameter ControlID="ddlProjectID" Name="project" 
                PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="ddlPad" Name="pad" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

Do you think that this will work.. I don't get any data for start date if I use more than one select parameters :?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.