Home All Groups Group Topic Archive Search About

How to add a dropdownlist to the column header in a GridView?

Author
18 Mar 2006 11:16 AM
Felix_WafyTech
Hello,

I would like to add a dropdownlist to the column header in a grid view to
facilitate filtering the records based on the selected value in the
dropdownlist. Is this possible? If yes, how do I accomplish that. Any help
is greatly appreciated.

Thanks,
Felix.J

Author
18 Mar 2006 1:41 PM
Felix_WafyTech
Hello,

I figured it out myself. However, the events for the dropdownlist are not
firing. Any ideas?

Thanks,
Felix.J


Show quoteHide quote
"Felix_WafyTech" <Felix_WafyTech@community.nospam> wrote in message
news:#oYgFynSGHA.1236@TK2MSFTNGP11.phx.gbl...
> Hello,
>
> I would like to add a dropdownlist to the column header in a grid view to
> facilitate filtering the records based on the selected value in the
> dropdownlist. Is this possible? If yes, how do I accomplish that. Any help
> is greatly appreciated.
>
> Thanks,
> Felix.J
>
>
Author
20 Mar 2006 6:16 AM
Steven Cheng[MSFT]
Hi Felix,

Thank you for posting.

As for adding a dropdownlist to gridview's certain column header and make
it sort the gridview when selectedIndex changes, I think you need to check
the following things:

1. Make sure the dropdownlist control has been set to AutoPostback = true,
this will make it postback whenever the client user change the selected
item in it.

2. Make sure the dropdownlist's "SelectedIndexChanged" event has been
attached an event handler (your custom event handler).

Here is the aspx template for a test gridview which contains a column which
embed a dropdownlist in it:

=======================
<Columns>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="True" CommandName="Update"
                            Text="Update"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton2" runat="server"
CausesValidation="False" CommandName="Cancel"
                            Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <HeaderTemplate>
                        <asp:DropDownList ID="lstSort" runat="server"
AutoPostBack="True" OnPreRender="lstSort_PreRender"

OnSelectedIndexChanged="lstSort_SelectedIndexChanged"
                       >
                            <asp:ListItem>CategoryID</asp:ListItem>
                            <asp:ListItem>CategoryName</asp:ListItem>
                            <asp:ListItem>Description</asp:ListItem>
                        </asp:DropDownList>
                    </HeaderTemplate>
...........................................

====================================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)