SORTING DATAGRID COLUMNS
-
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
-
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
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
-
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
:(( 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