.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

GridView Multicolumn sorting

Posted By:Shashi Ray       Posted Date: July 28, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

GridView Multicolumn sorting

GridView Multicolumn sorting

In Default.aspx


In Default.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page


      SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["abc"]);

      DataView dv = new DataView();

      DataSet ds;

      Class1 cls = new Class1();

protected void Page_Load(object sender, EventArgs e)


      if (!IsPostBack)


      dv = bindgrid();

      GridView1.DataSource = dv;





private DataView bindgrid()


      string StrQuery = "select st_code,dt_code,bk_code from bk_beneficiary";

      SqlDataAdapter sadp = new SqlDataAdapter(StrQuery, con);


      ds = new DataSet();



if (ViewState["Sorting"] != null)


      dv = new DataView(ds.Tables[0]);

      dv.Sort = (string)ViewState["Sorting"];




      dv = ds.Tables[0].DefaultView;


      return dv;


protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)


      ViewState["Sorting"] = e.SortExpression;

      GridView1.DataSource = bindgrid();




Shashi Kant Ray



Further Readings:

Author: netgrid         Company URL: http://www.dotnetspark.com
Posted Date: October 09, 2012

Really great article with very useful tips and advice .

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend