473,508 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another DataGrid Sorting problem

I have read many posts and seen many papers on the different
techniques for sort and filtering datagrids. Many do re-queries
against the dB ala Fritz Onion. I am trying to leverage the Dataview.
The following control simply responds to a sort request and/or a
pageing reqeust with an empty table (header only). Any ideas ?

Code behind :

namespace OakTree.data
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for AttendeeListControl.
/// </summary>
public class AttendeeListControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected OakTree.data.DataSet1 dataSet11;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
LoadData();

}

BindData();

}

DataView GetData()
{
DataSet ds = (DataSet)Session["Data"];

DataTable dt = ds.Tables[0];
return dt.DefaultView;

}

void LoadData()
{
//store the DataSet in Cache
oleDbDataAdapter1.Fill(dataSet11);

Session["Data"] = dataSet11;
}

void BindData()
{

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

DataGrid1.DataSource = dv.Table;
DataGrid1.DataMember = dv.Table.TableName;
// DataGrid1.DataKeyField = dv.Table.Columns[0].ColumnName;
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.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.dataSet11 = new OakTree.data.DataSet1();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
((System.ComponentModel.ISupportInitialize)(this.d ataSet11)).BeginInit();
this.DataGrid1.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.Handle_PageIndex_changed);
this.DataGrid1.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.Handle_sort);
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"User ID=sa;Data
Source=""SF-DDANIEL-XP"";Tag with column collation when
possible=False;Initial Catalog=Northwind;Use Procedure for
Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation
ID=""SF-DDANIEL-XP"";Use Encryption for Data=False;Packet Size=4096";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new
System.Globalization.CultureInfo("en-US");
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT ContactName,
CompanyName, Address, City, Region, PostalCode, Country, Phon" +
"e, Fax, CustomerID FROM Customers";
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = @"INSERT INTO
Customers(ContactName, CompanyName, Address, City, Region, PostalCode,
Country, Phone, Fax, CustomerID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
?); SELECT ContactName, CompanyName, Address, City, Region,
PostalCode, Country, Phone, Fax, CustomerID FROM Customers WHERE
(CustomerID = ?)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ContactName",
System.Data.OleDb.OleDbType.VarWChar, 30, "ContactName"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CompanyName",
System.Data.OleDb.OleDbType.VarWChar, 40, "CompanyName"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Address",
System.Data.OleDb.OleDbType.VarWChar, 60, "Address"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("City",
System.Data.OleDb.OleDbType.VarWChar, 15, "City"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Region",
System.Data.OleDb.OleDbType.VarWChar, 15, "Region"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("PostalCode",
System.Data.OleDb.OleDbType.VarWChar, 10, "PostalCode"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 15, "Country"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Phone",
System.Data.OleDb.OleDbType.VarWChar, 24, "Phone"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Fax",
System.Data.OleDb.OleDbType.VarWChar, 24, "Fax"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CustomerID",
System.Data.OleDb.OleDbType.VarWChar, 5, "CustomerID"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Select_CustomerI D",
System.Data.OleDb.OleDbType.VarWChar, 5, "CustomerID"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = @"UPDATE Customers SET
ContactName = ?, CompanyName = ?, Address = ?, City = ?, Region = ?,
PostalCode = ?, Country = ?, Phone = ?, Fax = ?, CustomerID = ? WHERE
(CustomerID = ?) AND (Address = ? OR ? IS NULL AND Address IS NULL)
AND (City = ? OR ? IS NULL AND City IS NULL) AND (CompanyName = ?) AND
(ContactName = ? OR ? IS NULL AND ContactName IS NULL) AND (Country =
? OR ? IS NULL AND Country IS NULL) AND (Fax = ? OR ? IS NULL AND Fax
IS NULL) AND (Phone = ? OR ? IS NULL AND Phone IS NULL) AND
(PostalCode = ? OR ? IS NULL AND PostalCode IS NULL) AND (Region = ?
OR ? IS NULL AND Region IS NULL); SELECT ContactName, CompanyName,
Address, City, Region, PostalCode, Country, Phone, Fax, CustomerID
FROM Customers WHERE (CustomerID = ?)";
this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ContactName",
System.Data.OleDb.OleDbType.VarWChar, 30, "ContactName"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CompanyName",
System.Data.OleDb.OleDbType.VarWChar, 40, "CompanyName"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Address",
System.Data.OleDb.OleDbType.VarWChar, 60, "Address"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("City",
System.Data.OleDb.OleDbType.VarWChar, 15, "City"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Region",
System.Data.OleDb.OleDbType.VarWChar, 15, "Region"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("PostalCode",
System.Data.OleDb.OleDbType.VarWChar, 10, "PostalCode"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 15, "Country"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Phone",
System.Data.OleDb.OleDbType.VarWChar, 24, "Phone"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Fax",
System.Data.OleDb.OleDbType.VarWChar, 24, "Fax"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CustomerID",
System.Data.OleDb.OleDbType.VarWChar, 5, "CustomerID"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Custome rID",
System.Data.OleDb.OleDbType.VarWChar, 5,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Address ",
System.Data.OleDb.OleDbType.VarWChar, 60,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 60,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_City",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "City", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_City1",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "City", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Company Name",
System.Data.OleDb.OleDbType.VarWChar, 40,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "CompanyName",
System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Contact Name",
System.Data.OleDb.OleDbType.VarWChar, 30,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "ContactName",
System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Contact Name1",
System.Data.OleDb.OleDbType.VarWChar, 30,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "ContactName",
System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Country 1",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Fax",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Fax1",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Phone",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Phone1" ,
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_PostalC ode",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_PostalC ode1",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Region" ,
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Region1 ",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Select_CustomerI D",
System.Data.OleDb.OleDbType.VarWChar, 5, "CustomerID"));
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = @"DELETE FROM Customers
WHERE (CustomerID = ?) AND (Address = ? OR ? IS NULL AND Address IS
NULL) AND (City = ? OR ? IS NULL AND City IS NULL) AND (CompanyName =
?) AND (ContactName = ? OR ? IS NULL AND ContactName IS NULL) AND
(Country = ? OR ? IS NULL AND Country IS NULL) AND (Fax = ? OR ? IS
NULL AND Fax IS NULL) AND (Phone = ? OR ? IS NULL AND Phone IS NULL)
AND (PostalCode = ? OR ? IS NULL AND PostalCode IS NULL) AND (Region =
? OR ? IS NULL AND Region IS NULL)";
this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Custome rID",
System.Data.OleDb.OleDbType.VarWChar, 5,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Address ",
System.Data.OleDb.OleDbType.VarWChar, 60,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 60,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_City",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "City", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_City1",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "City", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Company Name",
System.Data.OleDb.OleDbType.VarWChar, 40,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "CompanyName",
System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Contact Name",
System.Data.OleDb.OleDbType.VarWChar, 30,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "ContactName",
System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Contact Name1",
System.Data.OleDb.OleDbType.VarWChar, 30,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "ContactName",
System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Country 1",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Fax",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Fax1",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Phone",
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Phone1" ,
System.Data.OleDb.OleDbType.VarWChar, 24,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_PostalC ode",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_PostalC ode1",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Region" ,
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_Region1 ",
System.Data.OleDb.OleDbType.VarWChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original,
null));
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new
System.Data.Common.DataTableMapping("Table", "Customers", new
System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("ContactName" , "ContactName"),
new
System.Data.Common.DataColumnMapping("CompanyName" , "CompanyName"),
new
System.Data.Common.DataColumnMapping("Address", "Address"),
new
System.Data.Common.DataColumnMapping("City", "City"),
new
System.Data.Common.DataColumnMapping("Region", "Region"),
new
System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"),
new
System.Data.Common.DataColumnMapping("Country", "Country"),
new
System.Data.Common.DataColumnMapping("Phone", "Phone"),
new
System.Data.Common.DataColumnMapping("Fax", "Fax"),
new
System.Data.Common.DataColumnMapping("CustomerID", "CustomerID")})});
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.d ataSet11)).EndInit();

}
#endregion

private void Handle_sort(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
DataView dv = GetData();
dv.Sort = e.SortExpression;

DataGrid1.DataSource = dv;
DataGrid1.DataMember = dv.Table.TableName;
DataGrid1.DataBind();

}

private void Handle_PageIndex_changed(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}
}
Code in front:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="AttendeeListControl.ascx.cs"
Inherits="OakTree.data.AttendeeListControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<P>
<asp:DataGrid id=DataGrid1 runat="server" PageSize="20"
DataSource="<%# dataSet11 %>" DataMember="Customers"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Vertical"
ForeColor="Black" DataKeyField="CustomerID" AllowSorting="True"
AutoGenerateColumns="False" AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Black"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ContactName"
SortExpression="ContactName"
HeaderText="ContactName"></asp:BoundColumn>
<asp:BoundColumn DataField="CompanyName"
SortExpression="CompanyName"
HeaderText="CompanyName"></asp:BoundColumn>
<asp:BoundColumn DataField="City" SortExpression="City"
HeaderText="City"></asp:BoundColumn>
<asp:BoundColumn DataField="Region" SortExpression="Region"
HeaderText="Region"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="next &amp;gt;" PrevPageText="previous
&amp;lt;" HorizontalAlign="Center"
ForeColor="Black" Position="Top" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid></P>
Nov 18 '05 #1
2 1598
ddaniel,
Try something like this.
Jared

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then LoadData()
End Sub

Private Sub LoadData()
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString =
"Server=localhost;Database=Northwind;Trusted_Conne ction=True;"
conn.Open()
Dim da As New SqlClient.SqlDataAdapter("Select TitleOfCourtesy,
FirstName, LastName, Title FROM Employees Order By FirstName", conn)
Dim ds As New DataSet
da.Fill(ds)
conn.Close()
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataBind()
Dim reader As SqlClient.SqlDataReader
If viewstate.Item("ds") Is Nothing Then
viewstate.Add("ds", ds)
End If
End Sub

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
If viewstate.Item("SortExp") Is Nothing Then
viewstate.Add("SortExp", e.SortExpression)
Else
If viewstate.Item("SortExp") = e.SortExpression Then
viewstate.Item("SortExp") = e.SortExpression & " DESC"
Else
viewstate.Item("SortExp") = e.SortExpression
End If
End If
Sort()
End Sub

Private Sub Sort()
If Not viewstate.Item("ds") Is Nothing Then
Dim myds As DataSet = DirectCast(viewstate.Item("ds"), DataSet)
Dim dv As DataView = myds.Tables(0).DefaultView
dv.Sort = viewstate("SortExp")
Me.DataGrid1.DataSource = dv
Me.DataGrid1.DataBind()
End If
End Sub
"ddaniel" <da*********@yahoo.com> wrote in message
news:36**************************@posting.google.c om...
I have read many posts and seen many papers on the different
techniques for sort and filtering datagrids. Many do re-queries
against the dB ala Fritz Onion. I am trying to leverage the Dataview.
The following control simply responds to a sort request and/or a
pageing reqeust with an empty table (header only). Any ideas ?
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
LoadData();

}

BindData();
}

DataView GetData()
{
DataSet ds = (DataSet)Session["Data"];

DataTable dt = ds.Tables[0];
return dt.DefaultView;

}

void LoadData()
{
//store the DataSet in Cache
oleDbDataAdapter1.Fill(dataSet11);

Session["Data"] = dataSet11;
}

void BindData()
{

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

DataGrid1.DataSource = dv.Table;
DataGrid1.DataMember = dv.Table.TableName;
// DataGrid1.DataKeyField = dv.Table.Columns[0].ColumnName;
DataGrid1.DataBind();
}

private void Handle_sort(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
DataView dv = GetData();
dv.Sort = e.SortExpression;

DataGrid1.DataSource = dv;
DataGrid1.DataMember = dv.Table.TableName;
DataGrid1.DataBind();
}

private void Handle_PageIndex_changed(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}
}
Code in front:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="AttendeeListControl.ascx.cs"
Inherits="OakTree.data.AttendeeListControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<P>
<asp:DataGrid id=DataGrid1 runat="server" PageSize="20"
DataSource="<%# dataSet11 %>" DataMember="Customers"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Vertical"
ForeColor="Black" DataKeyField="CustomerID" AllowSorting="True"
AutoGenerateColumns="False" AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Black"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ContactName"
SortExpression="ContactName"
HeaderText="ContactName"></asp:BoundColumn>
<asp:BoundColumn DataField="CompanyName"
SortExpression="CompanyName"
HeaderText="CompanyName"></asp:BoundColumn>
<asp:BoundColumn DataField="City" SortExpression="City"
HeaderText="City"></asp:BoundColumn>
<asp:BoundColumn DataField="Region" SortExpression="Region"
HeaderText="Region"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="next &amp;gt;" PrevPageText="previous
&amp;lt;" HorizontalAlign="Center"
ForeColor="Black" Position="Top" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid></P>

Nov 18 '05 #2
When you step through the code does (DataSet)ViewState["Data"] contain your
data? Does ViewState["SortExp"] hold your sort expression? Try creating a
seperate page, drop in a new datagrid, connect to your database, use a
sample of data from your database (small select, three or four columns.),
have the columns generated dynamically, allow paging and sorting. Does it
work?

"ddaniel" <da*********@yahoo.com> wrote in message
news:36**************************@posting.google.c om...
Jared,

Thanks for the response the new code snippet looks like:

private void Sort()
{

if(ViewState["Data"]!=null)
{
DataSet ds= (DataSet)ViewState["Data"];
DataView dv= ds.Tables[0].DefaultView;
dv.Sort = (string)ViewState["SortExp"];
this.DataGrid1.DataSource = dv;
this.DataGrid1.DataBind();

}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
LoadData();

}

BindData();
}
void LoadData()
{
oleDbDataAdapter1.Fill(dataSet11);

if(this.ViewState["Data"] == null)
{
this.ViewState["Data"] = dataSet11;
}

}

void BindData()
{

this.DataGrid1.DataSource = dataSet11;
DataGrid1.DataBind();
}

private void Handle_sort(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
if (this.ViewState["SortExp"] == null)
{

ViewState.Add("SortExp" , e.SortExpression);
}
else if ((string)this.ViewState["SortExp"] == e.SortExpression)
{
ViewState["SortExp"] = e.SortExpression + " DESC";

}
else
{
ViewState["SortExp"] = e.SortExpression;

}
Sort();

}
the Init coe is the same as before. Still not responding with rows.
There must be something really dumb in there but I just Don't see it
!!!!!

Darin

"Jared" <VB***********@email.com> wrote in message
news:<10*************@corp.supernews.com>...
ddaniel,
Try something like this.
Jared

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then LoadData()
End Sub

Private Sub LoadData()
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString =
"Server=localhost;Database=Northwind;Trusted_Conne ction=True;"
conn.Open()
Dim da As New SqlClient.SqlDataAdapter("Select TitleOfCourtesy,
FirstName, LastName, Title FROM Employees Order By FirstName", conn)
Dim ds As New DataSet
da.Fill(ds)
conn.Close()
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataBind()
Dim reader As SqlClient.SqlDataReader
If viewstate.Item("ds") Is Nothing Then
viewstate.Add("ds", ds)
End If
End Sub

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
If viewstate.Item("SortExp") Is Nothing Then
viewstate.Add("SortExp", e.SortExpression)
Else
If viewstate.Item("SortExp") = e.SortExpression Then
viewstate.Item("SortExp") = e.SortExpression & " DESC"
Else
viewstate.Item("SortExp") = e.SortExpression
End If
End If
Sort()
End Sub

Private Sub Sort()
If Not viewstate.Item("ds") Is Nothing Then
Dim myds As DataSet = DirectCast(viewstate.Item("ds"), DataSet)
Dim dv As DataView = myds.Tables(0).DefaultView
dv.Sort = viewstate("SortExp")
Me.DataGrid1.DataSource = dv
Me.DataGrid1.DataBind()
End If
End Sub
"ddaniel" <da*********@yahoo.com> wrote in message
news:36**************************@posting.google.c om...
>I have read many posts and seen many papers on the different
> techniques for sort and filtering datagrids. Many do re-queries
> against the dB ala Fritz Onion. I am trying to leverage the Dataview.
> The following control simply responds to a sort request and/or a
> pageing reqeust with an empty table (header only). Any ideas ?
>

> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> LoadData();
>
> }
>
> BindData();
> }
>
> DataView GetData()
> {
> DataSet ds = (DataSet)Session["Data"];
>
> DataTable dt = ds.Tables[0];
> return dt.DefaultView;
>
> }
>
> void LoadData()
> {
> //store the DataSet in Cache
> oleDbDataAdapter1.Fill(dataSet11);
>
> Session["Data"] = dataSet11;
> }
>
> void BindData()
> {
>
> // Create a DataView from the DataTable.
> DataView dv = GetData();
>
> DataGrid1.DataSource = dv.Table;
> DataGrid1.DataMember = dv.Table.TableName;
> // DataGrid1.DataKeyField = dv.Table.Columns[0].ColumnName;
> DataGrid1.DataBind();
> }
>
> private void Handle_sort(object source,
> System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> {
> DataView dv = GetData();
> dv.Sort = e.SortExpression;
>
> DataGrid1.DataSource = dv;
> DataGrid1.DataMember = dv.Table.TableName;
> DataGrid1.DataBind();
> }
>
> private void Handle_PageIndex_changed(object source,
> System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
> {
>
>
> DataGrid1.CurrentPageIndex = e.NewPageIndex;
> BindData();
> }
> }
> }
>
>
> Code in front:
>
> <%@ Control Language="c#" AutoEventWireup="false"
> Codebehind="AttendeeListControl.ascx.cs"
> Inherits="OakTree.data.AttendeeListControl"
> TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
> <P>
> <asp:DataGrid id=DataGrid1 runat="server" PageSize="20"
> DataSource="<%# dataSet11 %>" DataMember="Customers"
> BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
> BackColor="White" CellPadding="3" GridLines="Vertical"
> ForeColor="Black" DataKeyField="CustomerID" AllowSorting="True"
> AutoGenerateColumns="False" AllowPaging="True">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#000099"></SelectedItemStyle>
> <AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="Black"></HeaderStyle>
> <FooterStyle BackColor="#CCCCCC"></FooterStyle>
> <Columns>
> <asp:BoundColumn DataField="ContactName"
> SortExpression="ContactName"
> HeaderText="ContactName"></asp:BoundColumn>
> <asp:BoundColumn DataField="CompanyName"
> SortExpression="CompanyName"
> HeaderText="CompanyName"></asp:BoundColumn>
> <asp:BoundColumn DataField="City" SortExpression="City"
> HeaderText="City"></asp:BoundColumn>
> <asp:BoundColumn DataField="Region" SortExpression="Region"
> HeaderText="Region"></asp:BoundColumn>
> </Columns>
> <PagerStyle NextPageText="next &amp;gt;" PrevPageText="previous
> &amp;lt;" HorizontalAlign="Center"
> ForeColor="Black" Position="Top" BackColor="#999999"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid></P>

Nov 18 '05 #3

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

Similar topics

0
1628
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
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...
2
3148
by: Hajime Kusakabe | last post by:
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like this .... ================================== Dim...
1
1168
by: bredal Jensen | last post by:
Hello, I'am experiencing that Asp.net can not handle sorting of datagrid when the number of items exceed a few thousands. Is anyone aware of this problem? The sorting works fine when the number...
4
2344
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....
2
3139
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
0
1032
by: Carl Tribble | last post by:
I have a datagrid in which I want to allow user to edit data and to sort the list by clicking a column header. When they have sorted the list, and subsequently make edits, the list automatically...
4
3084
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
0
2057
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
7323
Oralloy
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,...
1
7039
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...
0
7494
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...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
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...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.