0

フィルタリング/ソート機能が適切に機能するグリッドビューがあります。私の問題は、オンロードで、ヘッダーの直後に asc/desc イメージが表示されないことです。並べ替え画像は、任意のヘッダーをクリックした後にのみ表示されます。どんな助けでも大歓迎です。

コードビハインド:

#region Sorting Arrows for Gridview Header
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        foreach (TableCell tc in e.Row.Cells)
        {
            // search for the header link
            LinkButton lnk = (LinkButton)tc.Controls[0];
            if (tc.HasControls() && lnk != null && GridView1.SortExpression == lnk.CommandArgument)
            {
                // inizialize a new image
                System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                // setting the dynamically URL of the image
                img.ImageUrl = "~/Contents/Images/" + (GridView1.SortDirection == SortDirection.Ascending ? "asc" : "desc") + ".png";
                // adding a space and the image to the header link
                tc.Controls.Add(new LiteralControl(" "));
                tc.Controls.Add(img);
                //
            }
        }
    }
}
#endregion
4

1 に答える 1