Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SORTING DATAGRID COLUMNS

SORTING DATAGRID COLUMNS

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netgraphicsdesign
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3725115
    wrote on last edited by
    #1

    hi my dear friends, i have written code for sorting a datagrid column as given below.but its not working perfectly.please check the code and help me to over come this problem. thanks sumith **************************************************************** using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApplication1.images { public class sort : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack ) { BindGrid(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion public void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; BindGrid(); } public void DataGrid_Sort(object sender, DataGridSortCommandEventArgs e) { DataGrid1.CurrentPageIndex = 0; SortField = e.SortExpression; BindGrid(); } protected String SortField { get { object o = ViewState["SortField"]; return (o == null) ? String.Empty : (String)o; } set { ViewState["SortField"] = value; } } void BindGrid() { SqlConnection con3=new SqlConnection("server=localhost;Persist Security In

    S W 2 Replies Last reply
    0
    • M Member 3725115

      hi my dear friends, i have written code for sorting a datagrid column as given below.but its not working perfectly.please check the code and help me to over come this problem. thanks sumith **************************************************************** using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApplication1.images { public class sort : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack ) { BindGrid(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion public void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; BindGrid(); } public void DataGrid_Sort(object sender, DataGridSortCommandEventArgs e) { DataGrid1.CurrentPageIndex = 0; SortField = e.SortExpression; BindGrid(); } protected String SortField { get { object o = ViewState["SortField"]; return (o == null) ? String.Empty : (String)o; } set { ViewState["SortField"] = value; } } void BindGrid() { SqlConnection con3=new SqlConnection("server=localhost;Persist Security In

      S Offline
      S Offline
      Sylvester george
      wrote on last edited by
      #2

      SqlDataAdapter ad = new SqlDataAdapter("select * from Admin_ringtone ",con3); chnage the above line as SqlDataAdapter ad = new SqlDataAdapterCommandText ,con3);

      Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

      1 Reply Last reply
      0
      • M Member 3725115

        hi my dear friends, i have written code for sorting a datagrid column as given below.but its not working perfectly.please check the code and help me to over come this problem. thanks sumith **************************************************************** using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApplication1.images { public class sort : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack ) { BindGrid(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion public void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; BindGrid(); } public void DataGrid_Sort(object sender, DataGridSortCommandEventArgs e) { DataGrid1.CurrentPageIndex = 0; SortField = e.SortExpression; BindGrid(); } protected String SortField { get { object o = ViewState["SortField"]; return (o == null) ? String.Empty : (String)o; } set { ViewState["SortField"] = value; } } void BindGrid() { SqlConnection con3=new SqlConnection("server=localhost;Persist Security In

        W Offline
        W Offline
        www suniltvl in
        wrote on last edited by
        #3

        :(( if (flag == 0) { dv.Sort = e.SortExpression + " DESC"; flag = 1; } else { dv.Sort = e.SortExpression + " ASC"; flag = 0; } dv = dt.DefaultView; DataGriduser.DataSource = dv; DataGriduser.DataBind();

        Sunil Tvl

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups