ASP.NET 2.0 Gridview Column Ordering

Discussion in 'ASP .Net' started by John Walker, May 22, 2008.

  1. John Walker

    John Walker Guest

    Hi,

    In ASP.NET 2.0 I have a class called Cols (shown below) which keeps a record
    of the different columns in my gridview. I need this because sometimes I
    need to show/hide columns and need to know their position. One problem with
    this is that whenever we add a column to the gridview i need to add it to
    this Cols class and if it's at the beginning then every column after it has
    to be renumbered.
    Is there a way to somehow have the Cols fields auto number themselves, or is
    there an overall better way to keep track of your columns so it's easy to
    locate them for showing/hiding?

    Public Class Cols
    Public Shared Office As Int16 = 1
    Public Shared TruckerName As Int16 = 2
    Public Shared TruckerCode As Int16 = 3
    Public Shared TotalContainers As Int16 = 4
    Public Shared DOsNotReceived As Int16 = 5
    Public Shared DOsNotReceived__Pct As Int16 = 6
    Public Shared DOsPastDue As Int16 = 7
    Public Shared DOsPastDue__Pct As Int16 = 8
    Public Shared ContainersNotPickedUp As Int16 = 9
    Public Shared ContainersNotPickedUp__Pct As Int16 = 10
    Public Shared ContainersNotDelivered As Int16 = 11
    Public Shared ContainersNotDelivered__Pct As Int16 = 12
    Public Shared EmptiesNotPU As Int16 = 13
    Public Shared EmptiesNotPU__Pct As Int16 = 14
    Public Shared EmptiesNotReturned As Int16 = 15
    Public Shared EmptiesNotReturned__Pct As Int16 = 16
    Public Shared TotalMean As Int16 = 17
    End Class

    Thanks,
    John
    John Walker, May 22, 2008
    #1
    1. Advertising

  2. John Walker

    John Walker Guest

    Mark,
    Would you please give me an example of how to use Dictionary? I've never
    used that before.
    Thanks

    "Mark Rae [MVP]" wrote:

    > "John Walker" <> wrote in message
    > news:...
    >
    > > Is there a way to somehow have the Cols fields auto number themselves, or
    > > is
    > > there an overall better way to keep track of your columns so it's easy to
    > > locate them for showing/hiding?

    >
    > I have to say I'm scratching my head as to why you need a separate class
    > just for this...?
    >
    > Why not just use a generic e.g. Dictionary<string, int> or Dictionary<int,
    > string>...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    John Walker, May 22, 2008
    #2
    1. Advertising

  3. John Walker

    John Walker Guest

    "Mark Rae [MVP]" wrote:

    > "John Walker" <> wrote in message
    > news:...
    >
    > [top-posting corrected]
    >
    > >>> Is there a way to somehow have the Cols fields auto number themselves,
    > >>> or
    > >>> is there an overall better way to keep track of your columns so it's
    > >>> easy to
    > >>> locate them for showing/hiding?
    > >>
    > >> I have to say I'm scratching my head as to why you need a separate class
    > >> just for this...?
    > >>
    > >> Why not just use a generic e.g. Dictionary<string, int> or
    > >> Dictionary<int,
    > >> string>...?

    > >
    > > Would you please give me an example of how to use Dictionary? I've never
    > > used that before.

    >
    > http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >


    I see how that could work for me as i could programmatically assign the
    column order at runtime, though the great thing i find about using a Class is
    that intellisense will show me all the column names of the class so i dont
    have to remember the exact spelling.

    For example,
    dg.Columns(Cols.TruckerCode).Visible = False

    i would just need to remember that Cols is my class and then i just choose
    the column name from the list. i dont 100% understand the Dictionary but i
    did not see how to do something similar with intellisense.
    Thanks
    John Walker, May 22, 2008
    #3
    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. xerj

    XML ordering with gridview

    xerj, May 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    407
  2. Replies:
    1
    Views:
    240
  3. Keith G Hicks
    Replies:
    3
    Views:
    752
    Keith G Hicks
    Feb 18, 2008
  4. nbigaouette

    Z-Ordering (Morton ordering) question

    nbigaouette, Nov 5, 2009, in forum: C Programming
    Replies:
    2
    Views:
    2,095
  5. John Walker

    Gridview - Dynamic Column Ordering

    John Walker, Sep 19, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    136
    John Walker
    Sep 19, 2008
Loading...

Share This Page