【发布时间】:2011-10-07 00:24:22
【问题描述】:
我的 SortedAscendingHeaderStyle 和 SortedDescendingHeaderStyle 根本不工作
<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>
点击标题时行排序正确,但是当我使用 FireBug 检查标题时,它只显示:(这是升序排序时)
<th scope="col">
<a href="javascript:__doPostBack('ctl00$body$ctl00$grdProducts','Sort$Namekey')">Namekey</a>
</th>
ForeColor 和 CssClass 根本没有设置。
有人知道我做错了什么吗?
编辑:我背后的 C# 代码
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();
}
【问题讨论】:
-
愚蠢的问题,如果你硬刷新 Ctl+F5 会发生什么?
-
Firefox 询问我是否要“重新发送”,我点击它,然后列仍然排序,并且标题仍然没有类/样式。