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


Top 5 Contributors of the Month
david stephan

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;

      GridView1.DataBind();

}

}

 

private DataView bindgrid()

{

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

      SqlDataAdapter sadp = new SqlDataAdapter(StrQuery, con);

      con.Open();

      ds = new DataSet();

      sadp.Fill(ds);

      con.Close();

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

{

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

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

}

else

{

      dv = ds.Tables[0].DefaultView;

}

      return dv;

}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)

{

      ViewState["Sorting"] = e.SortExpression;

      GridView1.DataSource = bindgrid();

      GridView1.DataBind();

}

}

Shashi Kant Ray

 


     

Further Readings:

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

Really great article with very useful tips and advice .
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-grouping


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