6

I have a simple question about filters. I have 4 dropdown lists which filter the data in my web application from MySQL database table. The first dropdown list is already selected showing only one project_id but the others drop down lists displays all the possible values from the database - this is what I made so far.

But I want to display only the data values for that particular project selected.

It's ASP.NET 4.0, C# behind and MySQL database used. Any help will be appreciated. Thanks

2 Answers 2

6

check out following links for populating cascading drop down list.

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx

http://www.codeproject.com/KB/aspnet/CascadingDropDown.aspx

http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx

Code:

<table>
    <tr>
        <td>First</td>
        <td><asp:DropDownList ID="DDLFirst" runat="server"  AutoPostBack="true"
                onselectedindexchanged="DDLFirst_SelectedIndexChanged"></asp:DropDownList></td>
    </tr>
    <tr>
        <td>Secord</td>
        <td><asp:DropDownList ID="DDLSecond" runat="server" AutoPostBack="true"
                onselectedindexchanged="DDLSecond_SelectedIndexChanged">
            <asp:ListItem Text="Select" Value="Select"></asp:ListItem>    
            </asp:DropDownList></td>
    </tr>
    <tr>
        <td>Thrid</td>
        <td><asp:DropDownList ID="DDLThird" runat="server"><asp:ListItem Text="Select" Value="Select"></asp:ListItem>    </asp:DropDownList></td>
    </tr>
</table>

// Code behind protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // your code to bind the first drop downlist

        }
    }

    protected void DDLFirst_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DDLFirst.SelectedIndex > 0)
        {
            string FirstDDLValue = DDLFirst.SelectedItem.Value;
            // below your code to get the second drop down list value filtered on first selection


        }

    }

    protected void DDLSecond_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DDLSecond.SelectedIndex > 0)
        {
            string SecondDDLValue = DDLSecond.SelectedItem.Value;
            // below your code to get the third drop down list value filtered on Second selection


        }
    }
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you guys it really helped. So what I need is AJAX ToolKit and CascadignDropDown control.
Is there another way of doing this. Without the AJAX Toolkit.. somehow i does not work for me and i'm getting confused.. :[
You can do it by postback. when Dropdownlist SelectedIndexChanged event bind second dropdownlist. and on second selectedindexchanged bind third drowdownlist.
Hello again Pragnesh. I still don't have any success for that. Do you have some more info on how to use the postback and the SelectedIndexChanged event?
3

Filter the second dropdown datasource with selectedvalue of first dropdown control

see this article http://www.asp.net/data-access/tutorials/master-detail-filtering-with-two-dropdownlists-

1 Comment

Link's broken, and I can't edit as it's under six characters. URL should be asp.net/data-access/tutorials/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.