List Box Sort: ASP.net, C#
Posted on 2012-03-13
As stated before I have a table that binds to a list box.
The state names in the list box is displayed as below. I need the state name to sort ASC. My code is below, can someone look at it and tell me what I am doing wrong.
The state name is not sorting ASC. Thanks!
StateID StateName Abbrv
1 California CA
2 Illinois IL
3 Louisiana LA
4 Alabama AL
5 Mississippi MS
6 Pennsylvania PA
7 Alabama AL
DataTable dtUSStates = (DataTable)Session["Some_States"];
lbStates.DataSource = dtUSStates;
lbStates.DataValueField = "StateID";
lbStates.DataTextField = "StateName";
//Sort by state name
DataView dvUSStates = new DataView();
dvUSStates = dtUSStates.DefaultView;
dvUSStates.Sort = "StateName, StateID ASC";