You just need to implement sorting feature of grid view, you can use below sample code for the implementation, but you need to change it according to your requirement
Check this link
http://stackoverflow.com/questions/1253657/how-to-implement-sorting-functionality-in-gridview
http://stackoverflow.com/questions/8708582/asp-net-gridview-sorting-implementation-event-handling
private string GetSortDirection(string column)
{
string sortDirection = "DESC";
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "DESC"))
{
sortDirection = "ASC";
}
}
}
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtbl = ((DataSet)Session["myDataSet"]).Tables[0];
dtbl.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
GridView1.DataSource = dtbl;
GridView1.DataBind();
Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
Everything about SQL Server | Experience inside SQL Server -Mohammad Nizamuddin
No comments:
Post a Comment