Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Filter GridView using a dropdown list but only after page populates with appropriate data from Query String

Filter GridView using a dropdown list but only after page populates with appropriate data from Query String

Scheduled Pinned Locked Moved C#
databasesysadminquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjc225
    wrote on last edited by
    #1

    I am using a GridView on a page that will need to display data based on either a URL passed in with a QueryString OR fields passed from a form. This may return 50-500 records or so based on the state etc... If this is too many, (and only if this is too many) the user will be able to filter based on the occupation. I can get it to filter on query string AND state at the same time but not or sadly. I want it to default to all occupations after pulling from the DB based on state, (I tried setting the default value for occupation to -1) and then, the user can use the dropdown control to filter it more.

    <asp:dropdownlist id="ddlCategories" runat="server" appenddatabounditems="True" autopostback="True"
    datasourceid="sdsCategories" datatextfield="Occupation" datavaluefield="Occupation">
    <asp:listitem text="All Categories" value="-1">
    </asp:listitem>
    </asp:dropdownlist>
    <asp:sqldatasource id="sdsCategories" runat="server" connectionstring="<%$ ConnectionStrings:eventsConnectionString1 %>"
    selectcommand="SELECT [Occupation] FROM [Events]" ProviderName="<%$ ConnectionStrings:eventsConnectionString1.ProviderName %>">
    </asp:sqldatasource>

    <asp:gridview id="gvProducts" runat="server" datasourceid="sdsProducts" style="margin-top: 12px;" AllowSorting="True" AutoGenerateColumns="False">
    	<columns>
            <asp:BoundField DataField="EventTitle" HeaderText="EventTitle" SortExpression="EventTitle" />
            <asp:BoundField DataField="EventEndDate" HeaderText="EventEndDate" SortExpression="EventEndDate" DataFormatString="{0:MM/dd/yyyy}" />
            <asp:BoundField DataField="EventStartDate" HeaderText="EventStartDate" SortExpression="EventStartDate" DataFormatString="{0:MM/dd/yyyy}" />
            <asp:BoundField DataField="EventCity" HeaderText="EventCity" SortExpression="EventCity" />
            <asp:BoundField DataField="EventState" HeaderText="EventState" SortExpression="EventState" />
            <asp:BoundField DataField="Occupation" HeaderText="Occupation" SortExpression="Occupation" />
    	</columns>
    </asp:gridview>
    <asp:sqldatasource id="sdsProducts" runat="server" connectionstring="<%$ ConnectionStrings:eventsConnectionString2 %>"
    	selectcommand="SELECT \[EventTitle\], \[EventEndDate\], \[EventStartDate\], \[EventCity\], \[EventState\], \[Occupation\] FROM \[Events\] WHERE (\[EventState\] = ?)" ProviderName="<%$ ConnectionStrings:eventsConnectionString2.ProviderNa
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups