473,811 Members | 3,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid and Simple Sorting

Hi.

I am having a problem doing a simple sorting. Would someone be cool enough
to take a look and advise? It doesn't sort.

+++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;
using System.Data.Sql Client;

using Microsoft.Appli cationBlocks.Da ta;

namespace Wells.Complianc e.UI.SAR
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.P age
{
protected ComponentArt.We b.UI.Menu Menu1;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
protected System.Web.UI.H tmlControls.Htm lForm Form1;

private string m_sSortColumn = "";
private string m_sSortOrder = "";

private void Page_Load(objec t sender, System.EventArg s e)
{
//if (!IsPostBack)
//{
//if (m_sSortColumn == "")
//{
Session["SortColumn "] = "InsertDate ";
Session["SortOrder"] = " asc";
//}

BindGrid();
//DataGrid1.DataS ource = GetDataSource() ;
//DataGrid1.DataB ind();
//}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.DataGrid1. SortCommand += new
System.Web.UI.W ebControls.Data GridSortCommand EventHandler(th is.SortData);
this.DataGrid1. SelectedIndexCh anged += new
System.EventHan dler(this.DataG rid1_SelectedIn dexChanged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void DataGrid1_Selec tedIndexChanged (object sender,
System.EventArg s e)
{

}

private ICollection GetDataSource()
{
string sConn = ConfigurationSe ttings.AppSetti ngs["ConnectStr ing"];
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add( new DataColumn("Pac kageID", typeof(string)) );
dt.Columns.Add( new DataColumn("Sta tus", typeof(string)) );
dt.Columns.Add( new DataColumn("Ins ertDate", typeof(string)) );

SqlDataReader sdr = SqlHelper.Execu teReader(sConn, "spGetUnusualPa ckage");

while (sdr.Read())
{
dr = dt.NewRow();

dr[0] = sdr["PackageID"].ToString();
dr[1] = sdr["Status"].ToString();
dr[2] = sdr["InsertDate "].ToString();

dt.Rows.Add(dr) ;
}

// To persist the data source between posts to the server,
// store it in session state.
Session["Source"] = dt;
//Session["SortOrder"] = " asc";

DataView dv = new DataView(dt);
dv.Sort = Session["SortColumn "].ToString() +
Session["SortOrder"].ToString();

return dv;
}

private void SortData(Object sender, DataGridSortCom mandEventArgs e)
{
Session["SortColumn "] = (string) e.SortExpressio n;

if (Session["SortOrder"].ToString() == " desc")
Session["SortOrder"] = " asc";
else
Session["SortOrder"] = " desc";

BindGrid();

// Retrieve the data source from session state.
//DataTable dt = (DataTable) Session["Source"];

// Create a DataView from the DataTable.
//DataView dv = new DataView(dt);

// The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.

//dv.Sort = e.SortExpressio n; //+ m_sSortOrder;

// Re-bind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
//DataGrid1.DataS ource = dv;
//DataGrid1.DataB ind();
}

private void BindGrid()
{
DataGrid1.DataS ource = GetDataSource() ;
DataGrid1.DataB ind();
}
}
}

--
Be Cool!
Nov 22 '05 #1
1 1771
I don't know if this would help, but whenever I put the cursor on the column
haeder, it displays the following message:

javascript: __doPostBack(Da taGrid1$_ctl14_ ctl0', '')

Any help is appreciated.

"thejackofa ll" wrote:
Hi.

I am having a problem doing a simple sorting. Would someone be cool enough
to take a look and advise? It doesn't sort.

+++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;
using System.Data.Sql Client;

using Microsoft.Appli cationBlocks.Da ta;

namespace Wells.Complianc e.UI.SAR
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.P age
{
protected ComponentArt.We b.UI.Menu Menu1;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
protected System.Web.UI.H tmlControls.Htm lForm Form1;

private string m_sSortColumn = "";
private string m_sSortOrder = "";

private void Page_Load(objec t sender, System.EventArg s e)
{
//if (!IsPostBack)
//{
//if (m_sSortColumn == "")
//{
Session["SortColumn "] = "InsertDate ";
Session["SortOrder"] = " asc";
//}

BindGrid();
//DataGrid1.DataS ource = GetDataSource() ;
//DataGrid1.DataB ind();
//}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.DataGrid1. SortCommand += new
System.Web.UI.W ebControls.Data GridSortCommand EventHandler(th is.SortData);
this.DataGrid1. SelectedIndexCh anged += new
System.EventHan dler(this.DataG rid1_SelectedIn dexChanged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void DataGrid1_Selec tedIndexChanged (object sender,
System.EventArg s e)
{

}

private ICollection GetDataSource()
{
string sConn = ConfigurationSe ttings.AppSetti ngs["ConnectStr ing"];
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add( new DataColumn("Pac kageID", typeof(string)) );
dt.Columns.Add( new DataColumn("Sta tus", typeof(string)) );
dt.Columns.Add( new DataColumn("Ins ertDate", typeof(string)) );

SqlDataReader sdr = SqlHelper.Execu teReader(sConn, "spGetUnusualPa ckage");

while (sdr.Read())
{
dr = dt.NewRow();

dr[0] = sdr["PackageID"].ToString();
dr[1] = sdr["Status"].ToString();
dr[2] = sdr["InsertDate "].ToString();

dt.Rows.Add(dr) ;
}

// To persist the data source between posts to the server,
// store it in session state.
Session["Source"] = dt;
//Session["SortOrder"] = " asc";

DataView dv = new DataView(dt);
dv.Sort = Session["SortColumn "].ToString() +
Session["SortOrder"].ToString();

return dv;
}

private void SortData(Object sender, DataGridSortCom mandEventArgs e)
{
Session["SortColumn "] = (string) e.SortExpressio n;

if (Session["SortOrder"].ToString() == " desc")
Session["SortOrder"] = " asc";
else
Session["SortOrder"] = " desc";

BindGrid();

// Retrieve the data source from session state.
//DataTable dt = (DataTable) Session["Source"];

// Create a DataView from the DataTable.
//DataView dv = new DataView(dt);

// The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.

//dv.Sort = e.SortExpressio n; //+ m_sSortOrder;

// Re-bind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
//DataGrid1.DataS ource = dv;
//DataGrid1.DataB ind();
}

private void BindGrid()
{
DataGrid1.DataS ource = GetDataSource() ;
DataGrid1.DataB ind();
}
}
}

--
Be Cool!

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
945
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
2
8498
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must just be missing something. Basically, I have a .aspx page that is very simple and has a simple datagrid. All code is in the .cs page for the datagrid (hence, I'm doing all datagrid work programmatically). The datagrid is populated from a SQL table...
4
2356
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1. The database used is SqlServer 2000. 2. A Stored Procedure is dragged onto the page from the Server Explorer
4
2117
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in codebehind file. I am using c#. Thanks Manny
1
1799
by: simonyong | last post by:
hello, everyone im a newbie to asp.net, getting nut with just a simple stuff please give me some direction How to use dropdownlist when user select one of the method in dropdownlist The fields inside dropdownlist are personnel_number, firstname,lastname,email.position_title I have a datagrid that view out all my data when: ---1st time page load, user will key in firstname or lastname then result will be display in the datagrid ---2nd...
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.