Dono where i am going wrong , I have took an event for sorting , this is my code for sorting gridview it is working finee, but i am unable to add arrows to the girdview , the above i have tried but its not adding me arrows, how do i add arrows ??
i have tried some articles but i am unable to add arrows with ascending and descending , gridview is sorting when clicking on header rows , but need to display to the user that he can sort based on ascending arrows and descending arrows ...
protected void grdInformation_Sorting(object sender, GridViewSortEventArgs e)
{
if (CurrentSortExpression == e.SortExpression.ToString())
{
if (CurrentSortDirection == "asc")
CurrentSortDirection = "desc";
else
CurrentSortDirection = "asc";
}
else
{
CurrentSortExpression = e.SortExpression.ToString();
CurrentSortDirection = "asc";
}
if (e.SortExpression.Trim() == this.SortField)
{
this.sortDirection = (this.sortDirection == "DESC" ? "ASC" : "DESC");
}
else
{
this.sortDirection = "ASC";
}
ViewState["SortDirection"] = this.sortDirection;
this.SortField = e.SortExpression;
Bindinfo(GetInformation(ddlStatus.SelectedValue, ddlGroups.SelectedValue));
}
Please help ??
What I have tried:
This is my code for adding gridview with arrows..
Gridview is sorting by ascending and descending but i am unable to add arrows.
protected void grdInformation_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
if (cell.HasControls())
{
LinkButton button = cell.Controls[0] as LinkButton;
HtmlGenericControl gv = new HtmlGenericControl("div");
Label lnkName = new Label();
lnkName.Text = button.Text;
if (button != null)
{
Image imageSort = new Image();
imageSort.ImageUrl = "~/images/asc.png";
if (grdInformation.SortExpression == button.CommandArgument)
{
if (grdInformation.SortDirection == SortDirection.Ascending)
{
imageSort.ImageUrl = "~/images/desc.png";
}
else
{
imageSort.ImageUrl = "~/images/asc.png";
}
}
gv.Controls.Add(lnkName);
gv.Controls.Add(imageSort);
button.Controls.Add(gv);
}
}
}
}
}
}
}