【发布时间】:2011-07-25 12:55:06
【问题描述】:
下面的代码显示了在对 GridView 进行排序但 GridView SortExpression 返回 NULL 时添加升序降序图像。
知道为什么会这样吗?
protected void grvSample_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
if (tc.HasControls())
{
LinkButton lnk = (LinkButton)tc.Controls[0];
if (lnk != null)
{
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "~/Images/" + (grvSample.SortDirection == SortDirection.Ascending ? "asc" : "desc") + ".gif";
if (grvSample.SortExpression == lnk.CommandArgument)
{
// adding a space and the image to the header link
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(img);
}
}
}
}
}
}
【问题讨论】:
标签: .net asp.net visual-studio gridview