By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,630 Members | 1,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,630 IT Pros & Developers. It's quick & easy.

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

P: n/a
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;

}

}

}
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.