Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2007, 03:41 AM
Authorized User
 
Join Date: Aug 2006
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 8:datagrid sorting not working

hi friends,
 I have written the code as below for sorting the datagrid columns.but its not working.please check the code and help me to overcome my problem..
************************************************** *****************
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);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        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 Info=False;User ID=sa;password=sa;Initial Catalog=vms_database;Data Source=server0");
            string CommandText;
            if(SortField == String.Empty)
                CommandText = "select * from Admin_ringtone order by songname";
            else
                CommandText = "select * from Admin_ringtone order by" + SortField;
            SqlDataAdapter ad = new SqlDataAdapter("select * from Admin_ringtone ",con3);
            DataSet ds = new DataSet();
            ad.Fill(ds,"Admin_ringtone");
            DataGrid1.DataSource = ds;
            DataGrid1.DataBind();

        }
    }
}
__________________
sumith





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid sorting Amorous ASP.NET 1.x and 2.0 Application Design 1 September 30th, 2005 11:44 PM
Chapter 17 - DataGrid Sorting Example Appled BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 4 March 28th, 2005 03:13 PM
Sorting not working correct Vishal_7 ASP.NET 1.0 and 1.1 Professional 0 February 21st, 2005 01:28 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Sorting Is not working alyeng2000 ASP.NET 1.0 and 1.1 Basics 3 March 2nd, 2004 06:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.