Data Grid Sort Problem

Discussion in 'ASP .Net' started by thebison, Apr 10, 2006.

  1. thebison

    thebison Guest

    Hi all,

    I hope someone can help with this relatively simple problem.
    I am building a timesheet application using ASP.NET C# with Visual
    Studio 2003.As it is only a protoype application, my database has been
    made in MSDE.

    I've searched all over the web for the answer to this, but can't quite
    work it
    out. Basically, I am showing all Timesheet Entries in a DataGrid, by
    applying a DataView to a DataSet. This works fine, and now I need to
    sort the entries. I want my sort order to be done by ResourceID, Day.
    The problem is that my Database has the days of the week stored as a
    string (i.e. each entry will be for one of of the following
    'Mon','Tues','Weds', 'Thurs', 'Fri', 'Sat', 'Sun')

    The problem when sorting is that if I sort by 'Day', because it's a
    string it will do it alphabetically. Obviously this is wrong, I want
    it to sort it in the order of the days of the week as shown above. How
    would I go about achieving this? I thought about assigning values to
    each day when adding to the database (this is done by a drop-down list
    so Monday could =1, Tuesday =2, Weds = 3 etc). However when I then pull
    the data into the DataGrid, it will be stored as numbers, not Days.

    Does anyone have any suggestions as to how I could solve this? To
    re-iterate, I have a column called 'Day' which will contains one of the
    7 days of the week, and I wish to sort rows in 'Day' logical order.

    Thanks in advance

    Al
     
    thebison, Apr 10, 2006
    #1
    1. Advertising

  2. Do you also have a date associated with the day, if so use this to sort on,
    else you could add an additional column to the bound DataTable which stored
    an integer representing the day, hide this in the datagrid, but use it to
    sort on.

    --
    ( OHM ) - One Handed Man
    AKA Terry Burns - http://TrainingOn.net

    "thebison" <> wrote in
    message news:...
    > Hi all,
    >
    > I hope someone can help with this relatively simple problem.
    > I am building a timesheet application using ASP.NET C# with Visual
    > Studio 2003.As it is only a protoype application, my database has been
    > made in MSDE.
    >
    > I've searched all over the web for the answer to this, but can't quite
    > work it
    > out. Basically, I am showing all Timesheet Entries in a DataGrid, by
    > applying a DataView to a DataSet. This works fine, and now I need to
    > sort the entries. I want my sort order to be done by ResourceID, Day.
    > The problem is that my Database has the days of the week stored as a
    > string (i.e. each entry will be for one of of the following
    > 'Mon','Tues','Weds', 'Thurs', 'Fri', 'Sat', 'Sun')
    >
    > The problem when sorting is that if I sort by 'Day', because it's a
    > string it will do it alphabetically. Obviously this is wrong, I want
    > it to sort it in the order of the days of the week as shown above. How
    > would I go about achieving this? I thought about assigning values to
    > each day when adding to the database (this is done by a drop-down list
    > so Monday could =1, Tuesday =2, Weds = 3 etc). However when I then pull
    > the data into the DataGrid, it will be stored as numbers, not Days.
    >
    > Does anyone have any suggestions as to how I could solve this? To
    > re-iterate, I have a column called 'Day' which will contains one of the
    > 7 days of the week, and I wish to sort rows in 'Day' logical order.
    >
    > Thanks in advance
    >
    > Al
    >
     
    OHM \( One Handed Man \), Apr 10, 2006
    #2
    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. Amy Snyder

    Sort Dynamic Data Grid

    Amy Snyder, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    440
    Amy Snyder
    Dec 2, 2003
  2. Brian Henry

    sort image or style on data grid

    Brian Henry, Jul 14, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,068
    Joe Fallon
    Jul 15, 2004
  3. =?Utf-8?B?VmlkZHM=?=
    Replies:
    1
    Views:
    422
    =?Utf-8?B?SklHTkVTSA==?=
    Oct 9, 2007
  4. Navin
    Replies:
    1
    Views:
    744
    Ken Schaefer
    Sep 9, 2003
  5. Replies:
    9
    Views:
    429
    whisperjim
    Nov 27, 2008
Loading...

Share This Page