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. Web Development
  3. ASP.NET
  4. Changing Sort Direction in GridView

Changing Sort Direction in GridView

Scheduled Pinned Locked Moved ASP.NET
questionhelp
3 Posts 3 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.
  • A Offline
    A Offline
    AndyASPVB
    wrote on last edited by
    #1

    Hi I have a GridView which I have constructed using a template. For my links at the top of the gridview, I have buttons in order to allow users to sort the values in the columns. My question is whether I can programmatically change the sort direction to be a direction I want it to be on first click. In other words, if you click the button and the first direction is Ascending, then I want it to be Descending first on first click and vice versa. Can anyone help me, please?

    C J 2 Replies Last reply
    0
    • A AndyASPVB

      Hi I have a GridView which I have constructed using a template. For my links at the top of the gridview, I have buttons in order to allow users to sort the values in the columns. My question is whether I can programmatically change the sort direction to be a direction I want it to be on first click. In other words, if you click the button and the first direction is Ascending, then I want it to be Descending first on first click and vice versa. Can anyone help me, please?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Yes, of course you can do that. I'd typically have the button just set a flag and pass that to the SQL to change the sort order.

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      1 Reply Last reply
      0
      • A AndyASPVB

        Hi I have a GridView which I have constructed using a template. For my links at the top of the gridview, I have buttons in order to allow users to sort the values in the columns. My question is whether I can programmatically change the sort direction to be a direction I want it to be on first click. In other words, if you click the button and the first direction is Ascending, then I want it to be Descending first on first click and vice versa. Can anyone help me, please?

        J Offline
        J Offline
        jai_101
        wrote on last edited by
        #3

        You can Use ViewState to set the sort Direction of the Gridview on Button Click Event write the following Code : if (ViewState["SortDirection"] != "Asc" ||ViewState["SortDirection"] == null) ViewState["SortDirection"] == "Desc" else ViewState["SortDirection"] == "Asc" // Here dv is the dataView Object. Product is the Field in Gridview Based on that Field we Sort Asc or Des. dv.Sort = ViewState["Product"].ToString() + " "+ViewState["SortDirection"].ToString(); gvBusinessSourcingList.DataSource = dv; gvBusinessSourcingList.DataBind(); Ok, Bye Jai

        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