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. Datagrid sorting / Dataview sorting

Datagrid sorting / Dataview sorting

Scheduled Pinned Locked Moved Web Development
algorithmsxmlquestion
7 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.
  • S Offline
    S Offline
    sucharita
    wrote on last edited by
    #1

    Hi, Datagrid.Sort() doesnt seem to sort integers right. My code is something like this, this is a part of datagrid event: dgProductList.DataSource = catalogXml; dgProductList.CurrentPageIndex = e.NewPageIndex; //create a new dataview with xml data DataView dvCatalog = new DataView(catalogXml.Tables[0]); //provide sort expression from datagrid event dvCatalog.Sort = e.SortExpression; //assign data source dgProductList.DataSource = dvCatalog; //bind data dgProductList.DataBind(); The code works just fine for sorting any column but for integer column. When I click on a integer column to sort the result i get is: 23 234 2345 246 25 256 what i expect is obviously: 23 25 234 246 256 2345 Does anyone have any input on this? Appreciate your response. Thanks, Sucharita.

    G 1 Reply Last reply
    0
    • S sucharita

      Hi, Datagrid.Sort() doesnt seem to sort integers right. My code is something like this, this is a part of datagrid event: dgProductList.DataSource = catalogXml; dgProductList.CurrentPageIndex = e.NewPageIndex; //create a new dataview with xml data DataView dvCatalog = new DataView(catalogXml.Tables[0]); //provide sort expression from datagrid event dvCatalog.Sort = e.SortExpression; //assign data source dgProductList.DataSource = dvCatalog; //bind data dgProductList.DataBind(); The code works just fine for sorting any column but for integer column. When I click on a integer column to sort the result i get is: 23 234 2345 246 25 256 what i expect is obviously: 23 25 234 246 256 2345 Does anyone have any input on this? Appreciate your response. Thanks, Sucharita.

      G Offline
      G Offline
      Gavin Jeffrey
      wrote on last edited by
      #2

      The problem is it thinks that the integer column is a text column. could you give an example of how catalogXml.table[0] is populated ??

      S 1 Reply Last reply
      0
      • G Gavin Jeffrey

        The problem is it thinks that the integer column is a text column. could you give an example of how catalogXml.table[0] is populated ??

        S Offline
        S Offline
        sucharita
        wrote on last edited by
        #3

        Thanks for your response. I do a databind and bind the dataview to the datagrid. DataView.Sort() with a sort expression doesn't seem to work right. Is there a value i should be passing for sort expression to indicate the integer column?

        G 1 Reply Last reply
        0
        • S sucharita

          Thanks for your response. I do a databind and bind the dataview to the datagrid. DataView.Sort() with a sort expression doesn't seem to work right. Is there a value i should be passing for sort expression to indicate the integer column?

          G Offline
          G Offline
          Gavin Jeffrey
          wrote on last edited by
          #4

          no the sort is working fine but the problem is that it is sorting on string and not integer values. You can try changing the data type of the dataColumn something like - myTable.Columns[columnName].DataType = System.Type.GetType("int32"); This might throw an error (but its worth a try) something like - cannot change the type of a column that has already been filled with data.

          S 1 Reply Last reply
          0
          • G Gavin Jeffrey

            no the sort is working fine but the problem is that it is sorting on string and not integer values. You can try changing the data type of the dataColumn something like - myTable.Columns[columnName].DataType = System.Type.GetType("int32"); This might throw an error (but its worth a try) something like - cannot change the type of a column that has already been filled with data.

            S Offline
            S Offline
            sucharita
            wrote on last edited by
            #5

            catalogXml.Tables[0].Columns["Price"].DataType = System.Type.GetType("int32"); catalogXml.ReadXml( path ); if( !catalogXml.HasErrors ) { DataView dvCatalog = new DataView(catalogXml.Tables[0]); lblSortExpression.Text = e.SortExpression; dvCatalog.Sort = e.SortExpression; dgProductList.DataSource = dvCatalog; dgProductList.DataBind(); } I can't change the data type after there is data in it and cannot access myTable before loading the data! this somehow does not seem to work :(

            G 1 Reply Last reply
            0
            • S sucharita

              catalogXml.Tables[0].Columns["Price"].DataType = System.Type.GetType("int32"); catalogXml.ReadXml( path ); if( !catalogXml.HasErrors ) { DataView dvCatalog = new DataView(catalogXml.Tables[0]); lblSortExpression.Text = e.SortExpression; dvCatalog.Sort = e.SortExpression; dgProductList.DataSource = dvCatalog; dgProductList.DataBind(); } I can't change the data type after there is data in it and cannot access myTable before loading the data! this somehow does not seem to work :(

              G Offline
              G Offline
              Gavin Jeffrey
              wrote on last edited by
              #6

              have a look at the following link - http://www.dotnet247.com/247reference/msgs/56/283683.aspx Same problem as yours.

              S 1 Reply Last reply
              0
              • G Gavin Jeffrey

                have a look at the following link - http://www.dotnet247.com/247reference/msgs/56/283683.aspx Same problem as yours.

                S Offline
                S Offline
                sucharita
                wrote on last edited by
                #7

                Thanks, it was a great pointer. One needs to declare a Dataset and datatable. Add columns to table and specify the data type for the columns and then load the data set with any value. Really appreiciate your help.

                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