1
下面的代碼顯示了在對GridView進行排序時添加上下行圖像,但GridView的SortExpression返回NULL。Gridview SortExpression爲空
任何想法爲什麼會發生這種情況?
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);
}
}
}
}
}
}