473,473 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

confused by automatic object de-referencing

Hi,

Considering the code posted below can anyone explain to me why the following
behaviour occurs?

On page load the testFillDataGrid() function gets called and the variable
sel is successfully set to reference an instance of SqlSelect. The rest of
the code displays a DataGrid using a DataView and the source sorted by the
criteria specified in the sortString.

It all works great at this point!

The problem occurs when clicking on the column headings of the DataGrid
which causes DataGrid1_SortCommand() to execute, this sets the variable
sortString and calls bindDataGrid().

At this point dv no longer references a DataView object, dv now references
nothing at all! In fact any class variables I created now happily reference
nothing!

I can't figure this out because I thought that class variables persisted
until either the page is closed, or I dereference them myself.

(ps - sorry about the indenting, oe is playing silly buggers)

Thanks
Rich.


namespace PhoneReports
{
/// <summary>
/// Summary description for Results.
/// </summary>
public class Results : System.Web.UI.Page
{

private string sortString = "Date";
private SqlSelect sel = new SqlSelect();
private DataView dv = new DataView();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
testFillDataGrid();
}
}

private void testFillDataGrid()
{
string strSelect = "SELECT CONVERT(varchar(8),Date,5) AS Date, " +
"CONVERT(varchar(8),Time,8) AS Time, Country, [Number Dialled], " +
"Duration, Cost " +
"FROM [TBL Fixed Calls] " +
"WHERE [Billing Month] = '" + Session["month"].ToString() + "' " +
"AND [Account Number] = '" + Session["account"].ToString() + "' ";

sel = new SqlSelect(strSelect, component.sqlConn());
bindDataGrid();
}

private void bindDataGrid()
{
dv = new DataView(sel.getDataTable());
dv.Sort = sortString;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
sortString = e.SortExpression;
bindDataGrid();
}
}
}
Nov 16 '05 #1
1 1281
Hi,

Each time that you do a postback a NEW instance of the class ( page ) is
created, hence you have to REASSIGN your instance variables.
You can keep your datasource in session, then you do like this:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
testFillDataGrid();
}
else
{
// recover data from cache/session
}
}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"KavvY" <k@u.r> wrote in message
news:B7*******************@news-text.cableinet.net...
Hi,

Considering the code posted below can anyone explain to me why the following behaviour occurs?

On page load the testFillDataGrid() function gets called and the variable
sel is successfully set to reference an instance of SqlSelect. The rest of
the code displays a DataGrid using a DataView and the source sorted by the
criteria specified in the sortString.

It all works great at this point!

The problem occurs when clicking on the column headings of the DataGrid
which causes DataGrid1_SortCommand() to execute, this sets the variable
sortString and calls bindDataGrid().

At this point dv no longer references a DataView object, dv now references
nothing at all! In fact any class variables I created now happily reference nothing!

I can't figure this out because I thought that class variables persisted
until either the page is closed, or I dereference them myself.

(ps - sorry about the indenting, oe is playing silly buggers)

Thanks
Rich.


namespace PhoneReports
{
/// <summary>
/// Summary description for Results.
/// </summary>
public class Results : System.Web.UI.Page
{

private string sortString = "Date";
private SqlSelect sel = new SqlSelect();
private DataView dv = new DataView();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
testFillDataGrid();
}
}

private void testFillDataGrid()
{
string strSelect = "SELECT CONVERT(varchar(8),Date,5) AS Date, " +
"CONVERT(varchar(8),Time,8) AS Time, Country, [Number Dialled], " + "Duration, Cost " +
"FROM [TBL Fixed Calls] " +
"WHERE [Billing Month] = '" + Session["month"].ToString() + "' " +
"AND [Account Number] = '" + Session["account"].ToString() + "' ";

sel = new SqlSelect(strSelect, component.sqlConn());
bindDataGrid();
}

private void bindDataGrid()
{
dv = new DataView(sel.getDataTable());
dv.Sort = sortString;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
sortString = e.SortExpression;
bindDataGrid();
}
}
}

Nov 16 '05 #2

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

Similar topics

28
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all...
5
by: cedric buerfent | last post by:
Hello NG, I ve a question concerning automatic generated source code. When I program the declarations of a class (and save it in a file called myclass.hh for example), its a boring work to...
5
by: Wladimir Borsov | last post by:
Occasionally I want to save web pages (with the IE) without the surrounding frills and banners. For that I click on the link "print" and a printer friendly version web page is prepared and popped...
7
by: sunglo | last post by:
My doubt comes from trying to understand how thread return values work (I know, it's off topic here), and I'm wondering about the meaning of the "void **" parameter that pthread_join expects (I...
1
by: Stephan Keil | last post by:
Hi all, I am somewhat confused by the Object.GetHashCode() documentation. What I am looking for, is a hash code, which is bound to the _identity_ of an object, not to it's _value_ (see other...
1
by: Michel Esber | last post by:
Hello, Linux RedHat AS4 running DB2 V8 FP11. I have followed the docs at http://tinyurl.com/qckrn and enabled automatic statistics collection. It has been 2 days since I updated my DB cfg and...
26
by: Dodger | last post by:
Okay, background... yes, I am another of those evil, spurned, damnable Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung to understand something... I can write a script in...
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
1
by: falcon198198 | last post by:
Greetings: I was hoping for some advice on an application. Here is what I am working on: Basically I have a bigger application that is having a printing problem making multiple copies of a pdf...
0
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,...
0
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...
1
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
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.