2013-05-16 3 views
0

필터링/정렬 함수가 제대로 작동하는 gridview가 있습니다. 내 문제는 onload이며, 내 머리글 바로 뒤에 asc/desc 이미지가 표시되지 않습니다. 머리글을 클릭 한 후에 만 ​​이미지 정렬이 표시됩니다. 어떤 도움을 주시면 감사하겠습니다.gridview 헤더 이미지 추가 (오름차순/내림차순) onload

이 Codebehind가 :

#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 

답변

2

난 그냥 .. 그것을 알아 냈다

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); 
    } 
} 

감사합니다 ..