My SortedAscendingHeaderStyle and SortedDescendingHeaderStyle don't work at all
<asp:GridView ID="grdProducts" runat="server" CssClass="grid" AllowPaging="True" AllowSorting="True" PageSize="100" EmptyDataText="No data to show" onrowdatabound="grdProducts_RowDataBound" onrowediting="grdProducts_RowEditing" onsorting="grdProducts_Sorting" AutoGenerateEditButton="True"> <AlternatingRowStyle CssClass="even" /> <SortedAscendingHeaderStyle ForeColor="White" CssClass="sorted" /> <SortedDescendingHeaderStyle CssClass="sorted desc" /> </asp:GridView>
Lines are sorted correctly when headers are clicked, but when I check the header with FireBug, it only shows: (when sorting in ascending order)
<th scope="col"> <a href="javascript:__doPostBack('ctl00$body$ctl00$grdProducts','Sort$Namekey')">Namekey</a> </th>
ForeColor and CssClass are not installed at all.
Does anyone know what I'm doing wrong?
EDIT: my C # code is for
protected void grdProducts_Sorting(object sender, GridViewSortEventArgs e) { if ((string)ViewState["SortColumn"] == e.SortExpression) ViewState["SortDirection"] = ((string)ViewState["SortDirection"] == "") ? " DESC" : ""; else { ViewState["SortColumn"] = e.SortExpression; ViewState["SortDirection"] = ""; } } protected override void OnPreRender(EventArgs e) { BindGrid(); base.OnPreRender(e); } private void BindGrid() { string query = "SELECT ... ORDER BY " + ViewState["SortColumn"] + ViewState["SortDirection"]; DataTable dt = SqlFunctions.Select(query); grdProducts.DataSource = dt; grdProducts.DataBind(); }
Aximili
source share