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. GridView sorting

GridView sorting

Scheduled Pinned Locked Moved ASP.NET
algorithms
4 Posts 4 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.
  • B Offline
    B Offline
    Ballita
    wrote on last edited by
    #1

    Hi Can any one give me code for gridview sorting. I am using dataset as datasource of gridview.

    Thanks & Regards Mishra

    I V K 3 Replies Last reply
    0
    • B Ballita

      Hi Can any one give me code for gridview sorting. I am using dataset as datasource of gridview.

      Thanks & Regards Mishra

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Get it Sorting

      Best Regard
      Pathan

      1 Reply Last reply
      0
      • B Ballita

        Hi Can any one give me code for gridview sorting. I am using dataset as datasource of gridview.

        Thanks & Regards Mishra

        V Offline
        V Offline
        VenkataRamana Gali
        wrote on last edited by
        #3

        private DataSet GetData() { SqlConnection myConnection = new SqlConnection(ConnectionString); SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Categories", myConnection); DataSet ds = new DataSet(); ad.Fill(ds); return ds; } public SortDirection GridViewSortDirection { get { if (ViewState["sortDirection"] == null) ViewState["sortDirection"] = SortDirection.Ascending; return (SortDirection) ViewState["sortDirection"]; } set { ViewState["sortDirection"] = value; } } protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { string sortExpression = e.SortExpression; if (GridViewSortDirection == SortDirection.Ascending) { GridViewSortDirection = SortDirection.Descending; SortGridView(sortExpression, DESCENDING); } else { GridViewSortDirection = SortDirection.Ascending; SortGridView(sortExpression, ASCENDING); } } private void SortGridView(string sortExpression,string direction) { // You can cache the DataTable for improving performance DataTable dt = GetData().Tables[0]; DataView dv = new DataView(dt); dv.Sort = sortExpression + direction; GridView1.DataSource = dv; GridView1.DataBind(); }

        Ramana

        1 Reply Last reply
        0
        • B Ballita

          Hi Can any one give me code for gridview sorting. I am using dataset as datasource of gridview.

          Thanks & Regards Mishra

          K Offline
          K Offline
          Kasi Viswanathan
          wrote on last edited by
          #4

          Go to Properties of Grid View and Set Allow Sorting as TRUE

          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