CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 12/18/2003 12:42:26 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 36 Favorited: 0 Favorite
2 Items, 1 Pages 1 |< << Go >> >|
b0rdslide
Asp.Net User
Variables not retaining value12/18/2003 12:42:26 PM

0/0

Hi,

I have the following code-behind to one of my user controls:


namespace HipHopWardrobe.Affiliate.WebControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using HipHopWardrobe.Affiliate;

/// <summary>
/// Summary description for admin_approveaffiliatelist.
/// </summary>
public class admin_approveaffiliatelist : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid AffiliateList;
private string sortBy;
private string sortOrder;

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DoDataBind();
}
}

#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.AffiliateList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.AffiliateList_SortCommand);
this.AffiliateList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.AffiliateList_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DoDataBind()
{
DataTable affiliates = Affiliates.GetAffiliateDataTableByActive(true);

AffiliateList.DataSource = affiliates;
AffiliateList.DataBind();
}

private void AffiliateList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = (DataRowView)e.Item.DataItem;
}
}

private void AffiliateList_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if (sortBy == e.SortExpression)
{
switch (sortOrder)
{
case "ASC":
sortOrder = "DESC";
break;

case "DESC":
sortOrder = "ASC";
break;
}
}
else
{
sortBy = e.SortExpression;
sortOrder = "DESC";
}

DataTable affiliates = Affiliates.GetAffiliateDataTableByActive(true);
DataView data = new DataView(affiliates);
data.Sort = e.SortExpression + " " + sortOrder;
AffiliateList.DataSource = data;
AffiliateList.DataBind();
}
}
}


The problem I am having is that the sortBy and sortOrder vaiables are not retaining their value between postbacks. What would be causing them to be reset every time? Or am I just going about it the wrong way?

Thanks,
Kev
BN23 Search & Directory


Wilted Flower [W] http://www.bn23.com





EastbourneBeer


Wilted Flower [W] http://www.eastbournebeer.co.uk
tine2502
Asp.Net User
Re: Variables not retaining value12/18/2003 2:59:09 PM

0/0

I would store them in the Viewstate because now you are instanziating the variable on every postBack.

I propose to create a property like this:


public string sortBy{
get
{
if (ViewState["sortBy"]!=null) return (string) ViewState["sortBy"];
else return string.Empty;
}
set
{
ViewState["sortBy"] = value;
}
}



Then you can use the Property "sortBy" as usual but it keeps its value. You have to delete the variable from your "VariablesList" and do the same for sortOrder.

This should solve your problem.
Greetz
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
PHP Developer's Cookbook Authors: Sterling Hughes, Andrei Zmievski, Pages: 504, Published: 2001
Econometrics and the Philosophy of Economics: Theory-data Confrontations in Economics Authors: Bernt P. Stigum, Pages: 768, Published: 2003
Power SAS: A Survival Guide Authors: Kirk Paul Lafler, Pages: 291, Published: 2002
VHDL: Modular Design and Synthesis of Cores and Systems Authors: Zainalabedin Navabi, Pages: 556, Published: 2007
A Guide to Econometrics Authors: Peter Kennedy, Pages: 623, Published: 2003
Ecology and Conservation of the Marbled Murrelet Authors: C. John Ralph, George L. Hunt, Jr., Martin G. Raphael, John F. Piatt, Pages: 420, Published: 1997
Realising CIM's Industrial Potential: Proceedings of the Ninth CIM-Europe Annual Conference, 12-14 May 1993, RAI Amsterdam, the Netherlands Authors: C. Kooij, P. MacConaill, J. Bastos, Holland Elektronika, European Strategic Programme of Research and Development in Information Technology, Pages: 388, Published: 1993
Missing Data: A Gentle Introduction Authors: Patrick E. McKnight, Aurelio Jose Figueredo, Souraya Sidani, Pages: 251, Published: 2007
Fundamental Analysis: Fundamental Analysis Authors: Jack D. Schwager, Steven C. Turner, Pages: 639, Published: 1995

Web:
variable not retaining value - Shell Programming and Scripting ... Bourne shell Solaris I'm trying to set a flag to perform an action only when data is found. So I initialize the flag with: X=0 Then I read ...
VBA: Variable not retaining Value - Excel Help Best Practice Forums VBA: Variable not retaining Value EXCEL HELP. ... However, the variable data is getting lost after the CAll procedure. See code below ...
xsd variable - RE: Retaining value of a Global variable Subject: RE: Retaining value of a Global variable ... There could or could not be some articles with > article-classification as 'Webcasts'. ...
Variable not giving correct value - Mac Forums Variable not giving correct value iPhone Programming. ... I don't think you're retaining the variable. It's getting autoreleased. ...
Method for retaining the correction value of a control variable in ... As described above, the method of retaining a correction value in the volatile memory by supplying electric power while the engine control device is not ...
Urgent... Report Parameters not retaining values - SQL Server - LockOneForRead("TableName", ref variables); string tableName = variable.Value. ToString(); variables.Unlock() Tag: Urgent... Report Parameters not retaining ...
Variables retaining values Talk about Variables retaining values. ... You may not post new threads. You may not post replies. You may not post attachments ...
Closures retaining values. - CodingForums.com Closures retaining values. Computer Programming. ... this Closure1 function is called it will increment the value of the UpperValue variable ...
Mailing list archives Subject, Re: variables retaining value in #macro ... would it not be better if a variable inside macro did not get > > initialized, it had no value? ...
AS1-2 Retaining values within global variables - Oman3D.com Forum AS1-2 Retaining values within global variables Flash and ActionScript. ... But then the values did not display on the second loop. ...

Videos:
Charlie Rose - Analyzing the Avian Flu Threat An hour-long look at the threat of Avian Flu with: Sir Paul Nurse, President, Rockefeller University, Michael Leavitt, Secretary of Health & Human Se...




Search This Site:










is this 'good coding' - when to call dispose()

c# work flatfile

can we open executable files in asp.net?

requirements definition / uml

public virtual bool allowpaging { get; set; }

how to use smtp send mail with asp.net

suggestions on designing an asp.net web application?

session state configuration help

restart service

how to get this html address http://www.domain.com/temp/book__3j1v4k4lj7lh3e3p4l6li5h__.htm

calendar control

the dumbest ? of all...

hit counter

uploading error on site?

system.invalidcastexception: specified cast is not

clear all tables (membership, profile, users, ...) in sql 2005

how can i hold a really large number?

can't get application to run after xcopy

pass nt login to second webpage

user's datetime

databinding arraylist (no default member found error)

dynamically linking stylesheets

how to insert a variable into html code? <%=myvar %> doesn't evaluate?

master pages problem with content pages

redirecting users to a different page on session timeout

cannot get web page via response & request objects in thread...!

error with asp.net 2.0.50727.0

help with bits

stored procedures or on .cs page

get database type

  Privacy | Contact Us
All Times Are GMT