如何根据其他DropDownList的选择进行多个DropDownList更改

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何根据其他DropDownList的选择进行多个DropDownList更改相关的知识,希望对你有一定的参考价值。

我有以下ASP.net代码,我用来过滤我的GridView

<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="TasksUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
        <table style="width: 100%; padding: 0; margin: 0; border: 0; border-spacing: 0; border-collapse: separate;" class="GridviewTable">
            <tr>
                <td style="width: 25%;">
                    <asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateTaskName" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT [ATTR2739] 'Task Name' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 20%;">
                    <asp:DropDownList ID="ddlService" CssClass="chosen-select" DataSourceID="dsPopulateService" AutoPostBack="true" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlService_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateService" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT [ATTR2846] 'Service' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 11%;">
                    <asp:DropDownList ID="ddlStatus" CssClass="chosen-select" DataSourceID="dsPopulateStatus" AutoPostBack="true" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlStatus_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateStatus" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT [ATTR2812] 'Status' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 14%;">
                    <asp:DropDownList ID="ddlDueDate" CssClass="chosen-select" DataSourceID="dsPopulateDueDate" AutoPostBack="true" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlDueDate_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateDueDate" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT CONVERT(VARCHAR(14), [ATTR2752], 110) 'Due Date' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 15%;">
                    <asp:DropDownList ID="ddlOwner" CssClass="chosen-select" DataSourceID="dsPopulateOwner" AutoPostBack="true" DataValueField="Owner" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlOwner_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateOwner" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT [REALNAME] 'Owner' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 15%;">
                    <asp:DropDownList ID="ddlClient" CssClass="chosen-select" DataSourceID="dsPopulateClient" AutoPostBack="true" DataValueField="Client" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlClient_onSelectIndexChanged">
                        <asp:ListItem Text="All" Value="%"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="dsPopulateClient" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT DISTINCT [ATTR2799] 'Client' FROM HSI.RMOBJECTINSTANCE1224 CT INNER JOIN HSI.RMOBJECTINSTANCE1232 S ON CT.ATTR2846 = S.ATTR2821 INNER JOIN HSI.USERACCOUNT UA ON S.FK2852 = (UA.USERNUM * -1) WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
            </tr>
        </table>
        <asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="There is no data to display" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
            <Columns>
                <asp:HyperLinkField Target="_blank" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-Width="25%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Service" HeaderText="Service" SortExpression="Service" ItemStyle-Width="20%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-Width="10%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Due Date" HeaderText="Due Date" SortExpression="Due Date" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

我上面的ASP.net页面的代码隐藏:

protected void ddlTaskName_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlTaskName.SelectedItem.Text;
    ddlService.SelectedIndex = 0;
    ddlStatus.SelectedIndex = 0;
    ddlDueDate.SelectedIndex = 0;
    ddlClient.SelectedIndex = 0;
    ddlOwner.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2739 = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}
protected void ddlOwner_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlOwner.SelectedItem.Text;
    ddlService.SelectedIndex = 0;
    ddlStatus.SelectedIndex = 0;
    ddlDueDate.SelectedIndex = 0;
    ddlClient.SelectedIndex = 0;
    ddlTaskName.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND UA.REALNAME = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}
protected void ddlService_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlService.SelectedItem.Text;
    ddlTaskName.SelectedIndex = 0;
    ddlStatus.SelectedIndex = 0;
    ddlDueDate.SelectedIndex = 0;
    ddlClient.SelectedIndex = 0;
    ddlOwner.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2846 = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}
protected void ddlStatus_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlStatus.SelectedItem.Text;
    ddlService.SelectedIndex = 0;
    ddlTaskName.SelectedIndex = 0;
    ddlDueDate.SelectedIndex = 0;
    ddlClient.SelectedIndex = 0;
    ddlOwner.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2812 = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}
protected void ddlDueDate_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlDueDate.SelectedItem.Text;
    ddlService.SelectedIndex = 0;
    ddlStatus.SelectedIndex = 0;
    ddlTaskName.SelectedIndex = 0;
    ddlClient.SelectedIndex = 0;
    ddlOwner.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CONVERT(VARCHAR(14), CT.ATTR2752, 110) = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}
protected void ddlClient_onSelectIndexChanged(object sender, EventArgs e)
{
    string query = "";
    string strText = ddlClient.SelectedItem.Text;
    ddlService.SelectedIndex = 0;
    ddlStatus.SelectedIndex = 0;
    ddlDueDate.SelectedIndex = 0;
    ddlTaskName.SelectedIndex = 0;
    ddlOwner.SelectedIndex = 0;
    //MessageBox.Show(strText);

    DataTable taskData = new DataTable();
    if (strText == "All")
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2799 = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (ViewState["sortExp"].ToString() != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString());
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            TasksUpdatePanel.Update();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}

执行过滤GridView的功能:

public void PullData(string sortExp, string sortDir)
{
    string query = "";
    DataTable taskData = new DataTable();
    connString = ""; //the connection string is here
    if (ddlTaskName.SelectedIndex == 0 && ddlService.SelectedIndex == 0 && ddlStatus.SelectedIndex == 0 && ddlDueDate.SelectedIndex == 0 && ddlOwner.SelectedIndex == 0 && ddlClient.SelectedIndex == 0)
    {
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0";
    }
    else if (ddlTaskName.SelectedIndex > 0)
    {
        string strText = ddlTaskName.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2739 = '" + strText + "'";
    }
    else if (ddlService.SelectedIndex > 0)
    {
        string strText = ddlService.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2846 = '" + strText + "'";
    }
    else if (ddlStatus.SelectedIndex > 0)
    {
        string strText = ddlStatus.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2812 = '" + strText + "'";
    }
    else if (ddlDueDate.SelectedIndex > 0)
    {
        string strText = ddlDueDate.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CONVERT(VARCHAR(14), CT.ATTR2752, 110) = '" + strText + "'";
    }
    else if (ddlOwner.SelectedIndex > 0)
    {
        string strText = ddlClient.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND UA.REALNAME = '" + strText + "'";
    }
    else if (ddlClient.SelectedIndex > 0)
    {
        string strText = ddlClient.SelectedItem.Text;
        query = strMainQuery + " WHERE CT.ACTIVESTATUS = 0 AND CT.ATTR2799 = '" + strText + "'";
    }

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (sortExp != string.Empty)
            {
                //MessageBox.Show(sortExp);
                //MessageBox.Show(sortDir);
                myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}

我想要做的是,当用户从其中一个DropDownList选择一个选项时,其他DropDownList将更改为过滤的GridView的值,但因为DataSource是硬编码的,我无法做到。

一旦选择了DropDownList,我如何从过滤后的GridView过滤每个DropDownList

答案

虽然我完全建议你使用parameterized queries,这应该适合你(可能需要稍作调整,因为我看不到你的整个代码,当然)

此方法应生成有效的where子句。您可以在代码隐藏中的各种OnSelectedIndexChanged方法中使用此方法来防止大量复制/粘贴代码。

public string GenerateWhereClause()
{
    List<String> conditions = new List<String>();

    conditions.Add("(CT.ACTIVESTATUS = 0)");

    if (ddlTaskName.SelectedIndex > 0)
    {
        string strText = ddlTaskName.SelectedItem.Text;
        conditions.Add(String.Format("(CT.ATTR2739 = '{0}')", strText));
    }

    if (ddlService.SelectedIndex > 0)
    {
        string strText = ddlService.SelectedItem.Text;
        conditions.Add(String.Format("(CT.ATTR2846 = '{0}')", strText));
    }

    if (ddlStatus.SelectedIndex > 0)
    {
        string strText = ddlStatus.SelectedItem.Text;
        conditions.Add(String.Format("(CT.ATTR2812 = '{0}')", strText));
    }

    if (ddlDueDate.SelectedIndex > 0)
    {
        string strText = ddlDueDate.SelectedItem.Text;
        conditions.Add(String.Format("(CONVERT(VARCHAR(14), CT.ATTR2752, 110) = '{0}')", strText));
    }

    if (ddlOwner.SelectedIndex > 0)
    {
        string strText = ddlOwner.SelectedItem.Text;
        conditions.Add(String.Format("(UA.REALNAME = '{0}')", strText));
    }

    if (ddlClient.SelectedIndex > 0)
    {
        string strText = ddlClient.SelectedItem.Text;
        conditions.Add(String.Format("(CT.ATTR2799 = '{0}')", strText));
    }

    // You can add additional filters here.  This isn't the cleanest way of doing it, but it's fairly quick and easy as long as you don't intend to add many more filters.

    string conditionsJoined = String.Join(" AND ", conditions);
    string whereClause = String.Format(" WHERE {0}", conditionsJoined);
    return whereClause;
}

这是你的PullData方法的修改版本。 (请注意,我只更改了创建条件语句的顶部。

public void PullData(string sortExp, string sortDir)
{
    string query = String.Format("{0}{1}", strMainQuery, GenerateWhereClause());
    DataTable taskData = new DataTable();
    connString = ""; //the connection string is here

    using (SqlConnection conn = new SqlConnection(connString))
    {
        try
        {
            SqlCommand cmd = new SqlCommand(query, conn);

            // create data adapter
            SqlDataAdapter da = new SqlDataAdapter(query, conn);
            // this will query your database and return the result to your datatable

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);

            DataView myDataView = new DataView();
            myDataView = myDataSet.Tables[0].DefaultView;

            if (sortExp != string.Empty)
            {
                myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
            }

            yourTasksGV.DataSource = myDataView;
            yourTasksGV.DataBind();

            conn.Close();
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
}

以上是关于如何根据其他DropDownList的选择进行多个DropDownList更改的主要内容,如果未能解决你的问题,请参考以下文章

第二个Dropdownlist无法选择其他选项

如何在MVC 5中使用DropdownListFor在多个DropDownList中选择值

gridview中用dropdownlist更改值来筛选,更改dropdownlist之后无法进行checkbox选择

当用户从DropDownList选择其他选项时如何更改内容

在 KendoGrid 中重新绑定 DropDownList,取决于在同一行的其他 DropDownList 中选择的值

不能在DropDownList 中选择多个项