Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET GridView SortedAscendingHeaderStyle does not work
    primarykey
    data
    text
    <p>My <code>SortedAscendingHeaderStyle</code> and <code>SortedDescendingHeaderStyle</code> is not working at all</p> <pre><code>&lt;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"&gt; &lt;AlternatingRowStyle CssClass="even" /&gt; &lt;SortedAscendingHeaderStyle ForeColor="White" CssClass="sorted" /&gt; &lt;SortedDescendingHeaderStyle CssClass="sorted desc" /&gt; &lt;/asp:GridView&gt; </code></pre> <p>Rows are sorted correctly when headers are clicked, but when I inspect the header using FireBug, it only shows: (this is when sorted ascending)</p> <pre><code>&lt;th scope="col"&gt; &lt;a href="javascript:__doPostBack('ctl00$body$ctl00$grdProducts','Sort$Namekey')"&gt;Namekey&lt;/a&gt; &lt;/th&gt; </code></pre> <p>ForeColor and CssClass are not set at all.</p> <p>Anyone has any idea what I am doing wrong?</p> <p>EDIT: My C# code behind</p> <pre><code> 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(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload