Приведенный ниже код показывает добавление восходящих-нисходящих изображений при сортировке 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);
}
}
}
}
}
}