开发者

How sort data taking from database in C#

开发者 https://www.devze.com 2023-03-18 19:36 出处:网络
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 dropdo

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));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消