Asp.net 将gridview标题图像(asc/desc)添加到onload

Asp.net 将gridview标题图像(asc/desc)添加到onload,asp.net,image,gridview,header,Asp.net,Image,Gridview,Header,我有一个gridview,它的过滤/排序功能工作正常。我的问题是onload,它不会在标题后面显示asc/desc图像。排序图像仅在单击任何标题后显示。任何帮助都将不胜感激 代码隐藏: #region Sorting Arrows for Gridview Header protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlR

我有一个gridview,它的过滤/排序功能工作正常。我的问题是onload,它不会在标题后面显示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

我刚想出来

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {       
        Image img = new Image();
        img.ImageUrl = "~/Contents/Images/asc.png";
        GridView1.HeaderRow.Cells[1].Controls.Add(new LiteralControl(" "));
        GridView1.HeaderRow.Cells[1].Controls.Add(img);
    }
}
谢谢