There is state table that have statename and circode but they are not sorted in table.
I use OrderByAsc("StateName")
where StateName is a column name of state table. How I get sorted state in dropdownlist. I use subsonic to fetch da开发者_开发百科ta from database.
StateCollection stc = (new
StateController()).getInstance().WFetchAll(true);
ddlState.Items.Clear();
if(addAllStates)
ddlState.Items.Add(new ListItem("All States", "0"));
//ddlState.DataSource = State.FetchAll();
//ddlState.DataTextField = State.Columns.StateName;
//ddlState.DataValueField = State.Columns.CircleCode;
//ddlState.DataBind();
stc = stc.OrderByAsc("CircleCode");
stc.SaveAll();
foreach (State st in stc)
{
ddlState.Items.Add(new ListItem(st.CircleCode + "-" + st.StateName, st.CircleCode));
}
Try
foreach (State st in stc.OrderBy(s => s.StateName))
{
ddlState.Items.Add(new ListItem(st.CircleCode + "-" + st.StateName, st.CircleCode));
}
精彩评论