增加的GridView标题图片(ASC / DESC)的onload [英] adding gridview header image(asc/desc) onload
本文介绍了增加的GridView标题图片(ASC / DESC)的onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有正常工作的过滤/排序功能的GridView。我的问题是的onload,它并不显示递增/递减图像我的报头之后。排序图像只有点击任何头后显示。任何帮助将是AP preciated。
codebehind:
#地区的排序箭的GridView头
保护无效GridView1_RowCreated(对象发件人,GridViewRowEventArgs E)
{
如果(e.Row.RowType == DataControlRowType.Header)
{
的foreach(在e.Row.Cells TableCell的TC)
{
//搜索标题链接
LinkButton的LNK =(LinkButton的)tc.Controls [0];
如果(tc.HasControls()及和放大器; LNK = NULL&放大器;!&安培; GridView1.SortEx pression == lnk.CommandArgument)
{
// inizialize新形象
System.Web.UI.WebControls.Image IMG =新System.Web.UI.WebControls.Image();
//设置图像的动态网址
img.ImageUrl =〜/内容/图片/+(GridView1.SortDirection == SortDirection.AscendingASC:降序)+巴纽;
//添加空间和图象的头的链接
tc.Controls.Add(新LiteralControl());
tc.Controls.Add(IMG);
//
}
}
}
}
#endregion
解决方案
我只是想通了。
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(!Page.IsPostBack)
{
图片IMG =新的图像();
img.ImageUrl =〜/内容/图像/ asc.png
GridView1.HeaderRow.Cells [1] .Controls.Add(新LiteralControl());
GridView1.HeaderRow.Cells [1] .Controls.Add(IMG);
}
}
谢谢..
I have a gridview with filtering/sorting functions working properly. My problem is that onload, it does not show asc/desc image right after my header. Sorting image shows only after clicking any header. Any help would be appreciated.
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
解决方案
I just figured it out..
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);
}
}
Thanks..
这篇关于增加的GridView标题图片(ASC / DESC)的onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文