每次过滤GridView时如何填充DropDownList [英] How do I populate DropDownList each time the GridView is filtered

查看:48
本文介绍了每次过滤GridView时如何填充DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它是一个`GridView`,正上方我有`DropDownList`,它允许我过滤:



I have the following code which is a `GridView` and right above it I have `DropDownList` which allows me to filter:

    <table class="taskGridView">
        <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>

Here is the code which allows me to populate and filter the table:

<a href="http://jsfiddle.net/4hzprq6p/">http://jsfiddle.net/4hzprq6p/</a>





Now what is happening is when the page is loaded, the `GridView` is populated and also the `DropDownList` is populated. When I filter the `GridView` from one of the `DropDownList`, how do I modify my ASP.net page or code behind so the rest of the `DropDownList` is changed based on the filtered `GridView`?



Right now the `DropDownList` is hard coded, but I would like it to be dynamic so the `DropDownList` entried shows the data ONLY from the updated `GridView`.



Now what is happening is when the page is loaded, the `GridView` is populated and also the `DropDownList` is populated. When I filter the `GridView` from one of the `DropDownList`, how do I modify my ASP.net page or code behind so the rest of the `DropDownList` is changed based on the filtered `GridView`?

Right now the `DropDownList` is hard coded, but I would like it to be dynamic so the `DropDownList` entried shows the data ONLY from the updated `GridView`.

推荐答案

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:Sq lDataSource>
</td>
<td style=\"width: 20%;\">
<asp:DropDownList ID=\"ddlService\" CssClass=\"chosen-select\" DataSour ceID=\"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 [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 INNE R 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 [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 [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="<%


这篇关于每次过滤GridView时如何填充DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆