Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding collection to a asp.net DataGrid - order of columns display question

Reply
Thread Tools

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

 
 
David Laub
Guest
Posts: n/a
 
      08-03-2004
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.Veh icleNum))

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

if (!myReader.IsDBNull((int)ExcelVehicleColumnsSV.Man agerLastName))

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

if (!myReader.IsDBNull((int)ExcelVehicleColumnsSV.Man agerFirstName))

colSV.MgrFName =
myReader.GetString((int)ExcelVehicleColumnsSV.Mana gerFirstName).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;

}

}

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Display order of the Columns of a GridView possible? Jack ASP .Net Web Controls 2 05-24-2006 05:45 AM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
URGENT question about binding collection to a datagrid onitemdatabound ITnerd ASP .Net Datagrid Control 1 11-02-2003 11:55 AM
Columns and Inherited Datagrid...Active Schema does not support columns rob thomson ASP .Net Datagrid Control 0 09-04-2003 03:09 PM



Advertisments