Si8
Si8

Reputation: 9225

Why isn't the DropDownList filter not working for my GridView

I have the following code which has a DropDownList for each column in my GridView:

<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="TasksUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
        <table style="width: 100%;" border="0" cellpadding="0" cellspacing="1" class="GridviewTable">
            <tr>
                <td style="width: 25%;">
                    <asp:DropDownList ID="ddlTaskName" DataSourceID="dsPopulateTaskName" AutoPostBack="false" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true">
                        <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 LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 20%;">
                    <asp:DropDownList ID="ddlService" DataSourceID="dsPopulateService" AutoPostBack="false" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true">
                        <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 LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 15%;">
                    <asp:DropDownList ID="ddlStatus" DataSourceID="dsPopulateStatus" AutoPostBack="false" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true">
                        <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 LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 15%;">
                    <asp:DropDownList ID="ddlDueDate" DataSourceID="dsPopulateDueDate" AutoPostBack="false" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true">
                        <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 LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM WHERE CT.ACTIVESTATUS = 0"></asp:SqlDataSource>
                </td>
                <td style="width: 15%;">
                    <asp:DropDownList ID="ddlClient" DataSourceID="dsPopulateClient" AutoPostBack="false" DataValueField="Client" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true">
                        <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 LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM 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="15%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Due Date" HeaderText="Due Date" SortExpression="Due Date" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
            </Columns>
        </asp:GridView>
         <asp:SqlDataSource ID="dsdetails" runat="server" ConnectionString="<%$ConnectionStrings:gvConnString %>" SelectCommand="SELECT 'http://dmag.com/' + CAST(CT.OBJECTID AS VARCHAR) + '&classid=1224' 'Task Detail', CT.ATTR2846 'Service', CT.ATTR2812 'Status', CT.ATTR2752 'Due Date', CT.ATTR2739 'Task Name', CT.ATTR2799 'Client' FROM HSI.RMOBJECTINSTANCE1224 CT LEFT JOIN HSI.USERGROUP UG on CT.FK2743 = UG.USERGROUPNUM WHERE CT.ACTIVESTATUS = 0" FilterExpression=" [Task Name] Like '{4}%' and [Service] Like '{1}%' and [Status] Like '{2}%' and [Due Date] Like '{3}%' and [Client] Like '{5}%'">
        <FilterParameters>
            <asp:ControlParameter Name="Task Name" ControlID="ddlTaskName" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="Service" ControlID="ddlService" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="Status" ControlID="ddlStatus" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="Due Date" ControlID="ddlDueDate" PropertyName="SelectedValue" />
            <asp:ControlParameter Name="Client" ControlID="ddlClient" PropertyName="SelectedValue" />
        </FilterParameters>
        </asp:SqlDataSource>
    </ContentTemplate>
</asp:UpdatePanel>

The DropDownList is displaying the correct values for each column but when I select an option, the GridView is not filtering.

I am using UpdatePanel so the page doesn't do a Postback when sorting and hence the DropDownList AutoPostBack is set to false.

UPDATE: I am missing the DataSourceID from the GridView but it is because I am populating and sorting it from code-behind.

How can I fix the issue?

Upvotes: 0

Views: 506

Answers (1)

Devesh
Devesh

Reputation: 4550

Even with the updatepanel , it is not going to filter the data on the client side. It has to go server side to filter the data. You have to make

                AutoPostBack = true

and handle the

                SelectedIndex_Change event

and then you have call the

               updatepanel.update()

To handle the Change event, you have to apply the filter on the grid data source and bind the grid again.

Upvotes: 1

Related Questions