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. How to sort each row in a GridView based from a Field [RankOrder] from Database

How to sort each row in a GridView based from a Field [RankOrder] from Database

Scheduled Pinned Locked Moved ASP.NET
questiondatabasehelptutorial
4 Posts 2 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
    Muc_
    wrote on last edited by
    #1

    I need your help but have ideas but do not know how to implement them. What I want is that the order of how the groups will eventually appear in the gridview are read from the database. I have 1 to x groups. In my GridView, the data are displayed with BoundField. It looks like this. <a href="http://img1.immage.de/0802377aunbenannt.jpg">http://img1.immage.de/0802377aunbenannt.jpg</a>[<a href="http://img1.immage.de/0802377aunbenannt.jpg" target="_blank" title="New Window">^</a>] My question is how can sort each row?

    P M 2 Replies Last reply
    0
    • M Muc_

      I need your help but have ideas but do not know how to implement them. What I want is that the order of how the groups will eventually appear in the gridview are read from the database. I have 1 to x groups. In my GridView, the data are displayed with BoundField. It looks like this. <a href="http://img1.immage.de/0802377aunbenannt.jpg">http://img1.immage.de/0802377aunbenannt.jpg</a>[<a href="http://img1.immage.de/0802377aunbenannt.jpg" target="_blank" title="New Window">^</a>] My question is how can sort each row?

      P Offline
      P Offline
      PunkIsNotDead
      wrote on last edited by
      #2

      Hi Muc! I am Not quite sure what are you looking for :laugh: but maybe you need to program the sort event of gridview... something like

      protected void GV_MyData_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)
          {
              DataTable dt = GetDataTableSource()//Getting the data source of GV
              DataView dv = new DataView(dt);
              dv.Sort = sortExpression + direction;
              GV\_MyData.DataSource = dv;
              GV\_MyData.DataBind();
          }
      
          private const string ASCENDING = " ASC";
          private const string DESCENDING = " DESC";
          public SortDirection GridViewSortDirection
          {
              get
              {
                  if (ViewState\["sortDirection"\] == null)
                      ViewState\["sortDirection"\] = SortDirection.Ascending;
                  return (SortDirection)ViewState\["sortDirection"\];
              }
              set { ViewState\["sortDirection"\] = value; }
          }
      

      ... it maybe helps a little! good luck! ;)

      M 1 Reply Last reply
      0
      • P PunkIsNotDead

        Hi Muc! I am Not quite sure what are you looking for :laugh: but maybe you need to program the sort event of gridview... something like

        protected void GV_MyData_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)
            {
                DataTable dt = GetDataTableSource()//Getting the data source of GV
                DataView dv = new DataView(dt);
                dv.Sort = sortExpression + direction;
                GV\_MyData.DataSource = dv;
                GV\_MyData.DataBind();
            }
        
            private const string ASCENDING = " ASC";
            private const string DESCENDING = " DESC";
            public SortDirection GridViewSortDirection
            {
                get
                {
                    if (ViewState\["sortDirection"\] == null)
                        ViewState\["sortDirection"\] = SortDirection.Ascending;
                    return (SortDirection)ViewState\["sortDirection"\];
                }
                set { ViewState\["sortDirection"\] = value; }
            }
        

        ... it maybe helps a little! good luck! ;)

        M Offline
        M Offline
        Muc_
        wrote on last edited by
        #3

        Hi punkIsNotDead, what im askin myself is how i can sort my gridview depending on the rank column in the database? Its Loos like this http://img2.immage.de/09028ecclientpic.jpg[^] When one of the arrows is clicked on, for example Asceding then then the line should high slip. Let's say we click the down arrow for AEC, then its value must be recalculated, which would be called that previous rank_value [2] jumps to 1 And the value of 1 was is then 2 Once everything is to be bound to the GridView. http://img4.immage.de/09024bd3d3edbpic.jpg[^]

        1 Reply Last reply
        0
        • M Muc_

          I need your help but have ideas but do not know how to implement them. What I want is that the order of how the groups will eventually appear in the gridview are read from the database. I have 1 to x groups. In my GridView, the data are displayed with BoundField. It looks like this. <a href="http://img1.immage.de/0802377aunbenannt.jpg">http://img1.immage.de/0802377aunbenannt.jpg</a>[<a href="http://img1.immage.de/0802377aunbenannt.jpg" target="_blank" title="New Window">^</a>] My question is how can sort each row?

          M Offline
          M Offline
          Muc_
          wrote on last edited by
          #4

          Hi punkIsNotDead, what im askin myself is how i can sort my gridview depending on the rank column in the database? Its Loos like this <a href="http://img2.immage.de/09028ecclientpic.jpg">http://img2.immage.de/09028ecclientpic.jpg</a>[<a href="http://img2.immage.de/09028ecclientpic.jpg" target="_blank" title="New Window">^</a>] When one of the arrows is clicked on, for example Asceding then then the line should high slip. Let's say we click the down arrow for AEC, then its value must be recalculated, which would be called that previous rank_value [2] jumps to 1 And the value of 1 was is then 2 Once everything is to be bound to the GridView. <a href="http://img4.immage.de/09024bd3d3edbpic.jpg"></a> <a href="http://img4.immage.de/09024bd3d3edbpic.jpg">http://img4.immage.de/09024bd3d3edbpic.jpg</a>[<a href="http://img4.immage.de/09024bd3d3edbpic.jpg" target="_blank" title="New Window">^</a>]

          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