-
-
Sort Image for bound columns in GridView
by r4ramki on 5/15/2008 12:34:15 PM
-
1. Call grdGrid_Sorting onsorting event of GridView
2. set the variable GridViewSortDirection to "Asc" or "Desc" based on the sort direction.
2. call GridViewSortImages from the sorting method.
This is a generic code and should work without any modifications.
-
protected void grdGrid_Sorting(object sender, GridViewSortEventArgs e)
{
GridViewSortImages(grdGrid, e);
}
protected void GridViewSortImages(GridView grdView, GridViewSortEventArgs e)
{
foreach (TableCell cell in grdView.HeaderRow.Cells)
{
if (cell.HasControls())
{
LinkButton button = cell.Controls[0] as LinkButton;
if (button != null)
{
Image image = new Image();
image.ImageUrl = "images/spacer.gif";
if (e.SortExpression == button.CommandArgument)
{
if (GridViewSortDirection == "ASC")
image.ImageUrl = "images/downa.gif";
else
image.ImageUrl = "images/upa.gif";
}
cell.Controls.Add(image);
}
}
}
}
-
Refactor it!
-
its working.great
by fareedkhan on 6/2/2008 5:51:32 AM
-
Please log in to refactor the code!
Login