Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);


}

}

}

}



}
}
}
Posted
Updated 24-Apr-17 13:46pm

1 solution

 
Share this answer
 
Comments
Mahesh2223 25-Apr-17 1:12am    
Specified argument was out of the range of valid values.
Parameter name: index

LinkButton lbSort = (LinkButton)cell.Controls[0]; // Here i am getting error
Karthik_Mahalingam 25-Apr-17 3:15am    
refer
http://www.aspdotnet-suresh.com/2011/02/how-to-show-up-and-down-arrows-during.html
Mahesh2223 25-Apr-17 5:24am    
no that also gives me error, but i have done with the sorting with arrows, how do i place an arrow in gridview on pageload, once the user clicks den normal sorting should be done, how to do this??
Karthik_Mahalingam 25-Apr-17 11:38am    
put screenshot
Mahesh2223 27-Apr-17 10:39am    
Karthik please help ???
Question

https://www.codeproject.com/Questions/1184309/Grid-view-page-index-changing-giving-the-total-rec

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900