Sorting problem

Discussion in 'ASP .Net Datagrid Control' started by Arda Coskun, Aug 21, 2004.

  1. Arda Coskun

    Arda Coskun Guest

    Hi,

    I did sorting on Datagrid control for integers. However, there is a problem;
    when I sort ascending it makes> 23, 3, 44, 5 . But I want 3, 5, 23, 44.

    How can I solve this?

    I'm loading XML data, how can I tell the datagrid that the score column is
    containing integers?



    DataSet oData = new DataSet();

    oData.ReadXml(Server.MapPath("HighScores.xml"));

    DataView oView = new DataView(oData.Tables[0]);



    oView.Sort = "Score DESC";

    DataGrid1.DataSource = oView;

    DataGrid1.DataBind();





    Thanks,

    --
    Sarp Arda Coskun
     
    Arda Coskun, Aug 21, 2004
    #1
    1. Advertising

  2. Hi Sarp,

    From your description, I think the sorting problem is likely caused by the
    DataColumns' value in the Datatable, you can have a check in the certain
    columns's DataType. Because when sorting , different data type has
    different sorting behavior. As for the condition you met that the rows is
    sorted as
    23, 3, 44, 5

    It is likely that the columns is sorted as "string" type rather than int or
    long (number type). Please have a check and try manually set the
    DataColumns' DAtaType in the DataTable.

    Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Aug 21, 2004
    #2
    1. Advertising

  3. Arda Coskun

    Arda Coskun Guest

    Thanks Mr. Cheng, but how I didn't create a DataTable, how can I set that
    columns behavious as int?


    "Steven Cheng[MSFT]" <> wrote in message
    news:i2#...
    > Hi Sarp,
    >
    > From your description, I think the sorting problem is likely caused by the
    > DataColumns' value in the Datatable, you can have a check in the certain
    > columns's DataType. Because when sorting , different data type has
    > different sorting behavior. As for the condition you met that the rows is
    > sorted as
    > 23, 3, 44, 5
    >
    > It is likely that the columns is sorted as "string" type rather than int

    or
    > long (number type). Please have a check and try manually set the
    > DataColumns' DAtaType in the DataTable.
    >
    > Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    >
     
    Arda Coskun, Aug 22, 2004
    #3
  4. Arda Coskun

    Arda Coskun Guest

    I did;

    DataSet oData = new DataSet();

    oData.Tables.Add("HighScores");

    oData.ReadXml(Server.MapPath("HighScores.xml"));

    oData.Tables[0].Columns[2].DataType = Type.GetType("System.Int16");

    DataView oView = new DataView(oData.Tables[0]);

    oView.Sort = "Score DESC";

    DataGrid1.DataSource = oView;

    DataGrid1.DataBind();

    But it gives an error, you cannot change the type of column after you
    created it. What can I do, thanks?

    "Arda Coskun" <> wrote in message
    news:...
    > Thanks Mr. Cheng, but how I didn't create a DataTable, how can I set that
    > columns behavious as int?
    >
    >
    > "Steven Cheng[MSFT]" <> wrote in message
    > news:i2#...
    > > Hi Sarp,
    > >
    > > From your description, I think the sorting problem is likely caused by

    the
    > > DataColumns' value in the Datatable, you can have a check in the certain
    > > columns's DataType. Because when sorting , different data type has
    > > different sorting behavior. As for the condition you met that the rows

    is
    > > sorted as
    > > 23, 3, 44, 5
    > >
    > > It is likely that the columns is sorted as "string" type rather than int

    > or
    > > long (number type). Please have a check and try manually set the
    > > DataColumns' DAtaType in the DataTable.
    > >
    > > Thanks.
    > >
    > > Regards,
    > >
    > > Steven Cheng
    > > Microsoft Online Support
    > >
    > > Get Secure! www.microsoft.com/security
    > > (This posting is provided "AS IS", with no warranties, and confers no
    > > rights.)
    > >
    > > Get Preview at ASP.NET whidbey
    > > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    > >
    > >

    >
    >
     
    Arda Coskun, Aug 23, 2004
    #4
  5. what you will need to do is either parse the xml before you load it and
    change the type to int16 for the appropriate node or read in the xml as
    before, create another datatable with the correct schema and shallow copy
    the information to the new table

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Arda Coskun" <> wrote in message
    news:%...
    >I did;
    >
    > DataSet oData = new DataSet();
    >
    > oData.Tables.Add("HighScores");
    >
    > oData.ReadXml(Server.MapPath("HighScores.xml"));
    >
    > oData.Tables[0].Columns[2].DataType = Type.GetType("System.Int16");
    >
    > DataView oView = new DataView(oData.Tables[0]);
    >
    > oView.Sort = "Score DESC";
    >
    > DataGrid1.DataSource = oView;
    >
    > DataGrid1.DataBind();
    >
    > But it gives an error, you cannot change the type of column after you
    > created it. What can I do, thanks?
    >
    > "Arda Coskun" <> wrote in message
    > news:...
    >> Thanks Mr. Cheng, but how I didn't create a DataTable, how can I set that
    >> columns behavious as int?
    >>
    >>
    >> "Steven Cheng[MSFT]" <> wrote in message
    >> news:i2#...
    >> > Hi Sarp,
    >> >
    >> > From your description, I think the sorting problem is likely caused by

    > the
    >> > DataColumns' value in the Datatable, you can have a check in the
    >> > certain
    >> > columns's DataType. Because when sorting , different data type has
    >> > different sorting behavior. As for the condition you met that the rows

    > is
    >> > sorted as
    >> > 23, 3, 44, 5
    >> >
    >> > It is likely that the columns is sorted as "string" type rather than
    >> > int

    >> or
    >> > long (number type). Please have a check and try manually set the
    >> > DataColumns' DAtaType in the DataTable.
    >> >
    >> > Thanks.
    >> >
    >> > Regards,
    >> >
    >> > Steven Cheng
    >> > Microsoft Online Support
    >> >
    >> > Get Secure! www.microsoft.com/security
    >> > (This posting is provided "AS IS", with no warranties, and confers no
    >> > rights.)
    >> >
    >> > Get Preview at ASP.NET whidbey
    >> > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >> >
    >> >

    >>
    >>

    >
    >
     
    Alvin Bruney [MVP], Aug 23, 2004
    #5
  6. Arda Coskun

    Arda Coskun Guest

    I want to change the score column of my table. Here the code that I tried;

    oData.Tables[0].Columns.Add("Name");

    oData.Tables[0].Columns.Add("Country");

    oData.Tables[0].Columns.Add("Score");

    oData.Tables[0].Columns.Add("Level");

    oData.Tables[0].Columns[2].DataType = Type.GetType("System.Int16");

    oData.ReadXml(Server.MapPath("HighScores.xml"));

    but it showed me an empty datagrid.

    Could you please show me and example Alvin, thanks.

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > what you will need to do is either parse the xml before you load it and
    > change the type to int16 for the appropriate node or read in the xml as
    > before, create another datatable with the correct schema and shallow copy
    > the information to the new table
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Arda Coskun" <> wrote in message
    > news:%...
    > >I did;
    > >
    > > DataSet oData = new DataSet();
    > >
    > > oData.Tables.Add("HighScores");
    > >
    > > oData.ReadXml(Server.MapPath("HighScores.xml"));
    > >
    > > oData.Tables[0].Columns[2].DataType = Type.GetType("System.Int16");
    > >
    > > DataView oView = new DataView(oData.Tables[0]);
    > >
    > > oView.Sort = "Score DESC";
    > >
    > > DataGrid1.DataSource = oView;
    > >
    > > DataGrid1.DataBind();
    > >
    > > But it gives an error, you cannot change the type of column after you
    > > created it. What can I do, thanks?
    > >
    > > "Arda Coskun" <> wrote in message
    > > news:...
    > >> Thanks Mr. Cheng, but how I didn't create a DataTable, how can I set

    that
    > >> columns behavious as int?
    > >>
    > >>
    > >> "Steven Cheng[MSFT]" <> wrote in message
    > >> news:i2#...
    > >> > Hi Sarp,
    > >> >
    > >> > From your description, I think the sorting problem is likely caused

    by
    > > the
    > >> > DataColumns' value in the Datatable, you can have a check in the
    > >> > certain
    > >> > columns's DataType. Because when sorting , different data type has
    > >> > different sorting behavior. As for the condition you met that the

    rows
    > > is
    > >> > sorted as
    > >> > 23, 3, 44, 5
    > >> >
    > >> > It is likely that the columns is sorted as "string" type rather than
    > >> > int
    > >> or
    > >> > long (number type). Please have a check and try manually set the
    > >> > DataColumns' DAtaType in the DataTable.
    > >> >
    > >> > Thanks.
    > >> >
    > >> > Regards,
    > >> >
    > >> > Steven Cheng
    > >> > Microsoft Online Support
    > >> >
    > >> > Get Secure! www.microsoft.com/security
    > >> > (This posting is provided "AS IS", with no warranties, and confers no
    > >> > rights.)
    > >> >
    > >> > Get Preview at ASP.NET whidbey
    > >> > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
     
    Arda Coskun, Aug 24, 2004
    #6
  7. Hi Arda,

    I think the problem may caused by the xml file's schema or format not
    compatiable with the DataTable. Can you modify the xml file's format? If
    so, you can try first creating a DataTable which define the "score" column
    as a integer type and write it out as xml and then use this format. Other
    wise, I think you shoud consider Alvin's suggestion that create a new
    columns or new datatable and manually generate the new integer datas from
    the imported string data.
    Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Aug 25, 2004
    #7
  8. Steven Cheng[MSFT], Aug 27, 2004
    #8
  9. Arda Coskun

    Arda Coskun Guest

    Hi Steven,

    I couldn't acheive a solution with your suggested ideas, but I used an XSD
    file and indicate each column's behaviour. However, I also faced with
    another problem about writing an xml with an xsd via XmlTextWriter, I'd be
    happy if you can provide me an example.

    Thanks for your kind reply.

    "Steven Cheng[MSFT]" <> wrote in message
    news:U6sq$...
    > Hi Arda,
    >
    > Have you got any progress on this issue? If you have any further ideas,
    > please feel free to post here.
    > Thanks.
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
     
    Arda Coskun, Aug 27, 2004
    #9
  10. Hi Arda,

    Thanks for your followup. In fact the "writing an xml with an xsd" I mean
    is just manually create a DataSet which contains a DataTable which have a
    columns(type is int) and then write the Dataset's scheme out to file to
    have a look at t he certain columns 's schema definition. And the .net 's
    DataSet class contains the following method which will can help us directly
    get a DataSet 's schema xml string or output the scheme to a file.
    DataSet.GetXmlSchema
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemdatadatasetclassgetxmlschematopic.asp

    DataSet.WriteXmlSchema
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataDataSetCla
    ssWriteXmlSchemaTopic.asp?frame=true

    in addition, when creating an new DataSet, we can also apply a existing
    schema on it. Just use the
    DataSet.InferXmlSchema
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemdatadatasetclassgetxmlschematopic.asp


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Aug 28, 2004
    #10
  11. Hi Arda,

    Have you got any futher ideas on this issue? If you have anything unclear
    or if there are anything else we can help, please feel free to post here.
    Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Sep 1, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hajime Kusakabe

    DataGrid - sorting/paging problem

    Hajime Kusakabe, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    502
    Saravana
    Jul 31, 2003
  2. Replies:
    2
    Views:
    1,491
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    412
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    514
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    170
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page