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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace Wells.Compliance.UI.SAR
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected ComponentArt.Web.UI.Menu Menu1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
private string m_sSortColumn = "";
private string m_sSortOrder = "";
private void Page_Load(object sender, System.EventArgs e)
{
//if (!IsPostBack)
//{
//if (m_sSortColumn == "")
//{
Session["SortColumn"] = "InsertDate";
Session["SortOrder"] = " asc";
//}
BindGrid();
//DataGrid1.DataSource = GetDataSource();
//DataGrid1.DataBind();
//}
}
#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.DataGrid1.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.SortData);
this.DataGrid1.SelectedIndexChanged += new
System.EventHandler(this.DataGrid1_SelectedIndexCh anged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
}
private ICollection GetDataSource()
{
string sConn = ConfigurationSettings.AppSettings["ConnectString"];
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("PackageID", typeof(string)));
dt.Columns.Add(new DataColumn("Status", typeof(string)));
dt.Columns.Add(new DataColumn("InsertDate", typeof(string)));
SqlDataReader sdr = SqlHelper.ExecuteReader(sConn, "spGetUnusualPackage");
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, DataGridSortCommandEventArgs e)
{
Session["SortColumn"] = (string) e.SortExpression;
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.SortExpression; //+ m_sSortOrder;
// Re-bind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
//DataGrid1.DataSource = dv;
//DataGrid1.DataBind();
}
private void BindGrid()
{
DataGrid1.DataSource = GetDataSource();
DataGrid1.DataBind();
}
}
}
--
Be Cool! 1 1753
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(DataGrid1$_ctl14_ctl0', '')
Any help is appreciated.
"thejackofall" 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.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Configuration; using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace Wells.Compliance.UI.SAR { /// <summary> /// Summary description for index. /// </summary> public class index : System.Web.UI.Page { protected ComponentArt.Web.UI.Menu Menu1; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.HtmlControls.HtmlForm Form1;
private string m_sSortColumn = ""; private string m_sSortOrder = "";
private void Page_Load(object sender, System.EventArgs e) { //if (!IsPostBack) //{ //if (m_sSortColumn == "") //{ Session["SortColumn"] = "InsertDate"; Session["SortOrder"] = " asc"; //}
BindGrid(); //DataGrid1.DataSource = GetDataSource(); //DataGrid1.DataBind(); //} }
#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.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.SortData); this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexCh anged); this.Load += new System.EventHandler(this.Page_Load);
} #endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e) {
}
private ICollection GetDataSource() { string sConn = ConfigurationSettings.AppSettings["ConnectString"]; DataTable dt = new DataTable(); DataRow dr;
dt.Columns.Add(new DataColumn("PackageID", typeof(string))); dt.Columns.Add(new DataColumn("Status", typeof(string))); dt.Columns.Add(new DataColumn("InsertDate", typeof(string)));
SqlDataReader sdr = SqlHelper.ExecuteReader(sConn, "spGetUnusualPackage");
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, DataGridSortCommandEventArgs e) { Session["SortColumn"] = (string) e.SortExpression;
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.SortExpression; //+ m_sSortOrder;
// Re-bind the data source and specify that it should be sorted // by the field specified in the SortExpression property. //DataGrid1.DataSource = dv; //DataGrid1.DataBind(); }
private void BindGrid() { DataGrid1.DataSource = GetDataSource(); DataGrid1.DataBind(); } } }
-- Be Cool! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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....
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |