Binding collection to a asp.net DataGrid - order of columns display question

Discussion in 'ASP .Net' started by David Laub, Aug 3, 2004.

  1. David Laub

    David Laub Guest

    When I bind a collection to a DataGrid (with teh single statement DataBind),
    I love that the property names become the column names/values for the grid.
    But I HATE that the columns are (seemingly?) displayed in random order -
    i.e. I define a class with three properties: VehicleNumber, MgrLName, and
    MgrFName. The grid displays as follows, which is neither the order in which
    the properties were defined, or alphabetical order.

    Can any one help me display these columns in the order I want
    (VehicleNumber, MgrLName, and MgrFName)

    MgrLName VehicleNumber MgrFName
    Albritton 0294E John
    Albritton 0294E John
    Albritton 0294E John


    private ArrayList spreadsheetSVRowsClass = new ArrayList();

    ExcelVehicleColumnsSVClass colSV = new ExcelVehicleColumnsSVClass();

    if (!myReader.IsDBNull((int)ExcelVehicleColumnsSV.VehicleNum))

    colSV.VehicleNumber =
    myReader.GetString((int)ExcelVehicleColumnsSV.VehicleNum).Trim();

    if (!myReader.IsDBNull((int)ExcelVehicleColumnsSV.ManagerLastName))

    colSV.MgrLName =
    myReader.GetString((int)ExcelVehicleColumnsSV.ManagerLastName).Trim();

    if (!myReader.IsDBNull((int)ExcelVehicleColumnsSV.ManagerFirstName))

    colSV.MgrFName =
    myReader.GetString((int)ExcelVehicleColumnsSV.ManagerFirstName).Trim();

    spreadsheetSVRowsClass.Add(colSV);

    DataGrid1.DataSource = spreadsheetSVRowsClass;

    DataGrid1.DataBind();

    class ExcelVehicleColumnsSVClass

    {

    private string vehicleNumber;

    private string mgrLName;

    private string mgrFName;

    public string VehicleNumber

    {

    get

    {

    return vehicleNumber;

    }

    set

    {

    vehicleNumber = value;

    }

    }

    public string MgrLName

    {

    get

    {

    return mgrLName;

    }

    set

    {

    mgrLName = value;

    }

    }

    public string MgrFName

    {

    get

    {

    return mgrFName;

    }

    set

    {

    mgrFName = value;

    }

    }

    }
     
    David Laub, Aug 3, 2004
    #1
    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. Jimmy
    Replies:
    1
    Views:
    3,161
    Eliyahu Goldin
    Jun 14, 2005
  2. Øyvind Isaksen
    Replies:
    1
    Views:
    980
    Øyvind Isaksen
    May 18, 2007
  3. ITnerd
    Replies:
    1
    Views:
    138
    Giorgio Parmeggiani
    Nov 2, 2003
  4. JcFx
    Replies:
    0
    Views:
    281
  5. Jimmy
    Replies:
    2
    Views:
    188
    Kim Quigley
    Jun 16, 2005
Loading...

Share This Page