Gridview SortExpression with 2 fields
Posted
by aron
on Stack Overflow
See other posts from Stack Overflow
or by aron
Published on 2010-04-12T19:21:09Z
Indexed on
2010/04/12
19:23 UTC
Read the original article
Hit count: 160
Hello, I have a GridView that get's its datasource from a complex object. So I'm doing the Sorting & Paging in the code behind.
<asp:GridView ID="SystemsDetailList" runat="server" AllowSorting="true" AllowPaging="true"
AutoGenerateColumns="False" ShowFooter="True" OnPageIndexChanging="gridView_PageIndexChanging" OnSorting="gridView_Sorting">
For an important title column I have a SortExpression with 2 fields:
SortExpression="FunctionalAreaDisplayCode, EswbsDisplayCode"
This in the code behind:
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
BindSystemList(e.SortExpression, sortOrder);
}
public string sortOrder
{
get
{
if (ViewState["sortOrder"].ToString() == "desc")
{
ViewState["sortOrder"] = "asc";
}
else
{
ViewState["sortOrder"] = "desc";
}
return ViewState["sortOrder"].ToString();
}
set
{
ViewState["sortOrder"] = value;
}
}
For some reason it will keep "FunctionalAreaDisplayCode" always sorted ASC but the EswbsDisplayCode works fine as it flips between ASC and DESC correctly.
and tips here?
thanks!
© Stack Overflow or respective owner