I wish to change the gridview sort image at run time after the sorting on particular column is done so that user can identify which column and in which direction the sorting is done.
Say, there are 10 columns, Customer ID, Name 开发者_如何转开发etc. I did a descending sort on Customer Name, then the descending sort image should change to some other image so that it becomes easy to identify.
How is that possible?
the below is how i would do and this is a working solution and it works:
OnRowCreated="gvInActive_RowCreated"
protected void gvInActive_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (!(e.Row == null) && e.Row.RowType == DataControlRowType.Header)
{
#region sorting
foreach (TableCell cell in e.Row.Cells)
{
if (cell.HasControls())
{
if (cell.Controls[0].ToString() != "System.Web.UI.LiteralControl")
{
LinkButton button = (LinkButton)cell.Controls[0];
if (!(button == null))
{
System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
//image.ImageUrl = "images/nosort.gif";
image.Visible = false;
if (this.gvInactive.SortExpression == button.CommandArgument)
{
if (gvInactive.SortDirection == System.Web.UI.WebControls.SortDirection.Ascending)
{
image.Visible = true;
image.ImageUrl = "../../images/sort_asc.gif";
}
else
{
image.Visible = true;
image.ImageUrl = "../../images/sort_desc.gif";
}
}
//else
//{
// image.Visible = true;
// image.ImageUrl = "images/sort_none.gif";
//}
cell.Controls.Add(image);
}
}
}
}
#endregion
}
}
精彩评论