binding class variable to aspx page

  • Thread starter Thread starter Andrew Pasetti
  • Start date Start date
A

Andrew Pasetti

I'm having trouble binding/displaying a class variable to
the display aspx page. Perhaps someone can suggest what I
am doing wrong.

###################################
Within the .aspx page I have this:
###################################
<td><%# p.ParcelName %></td>

#############################################
Within the code-behind page I have this:
#############################################
private void Page_Load(object sender, System.EventArgs e)
{
ParcelBusiness p = new ParcelBusiness(Convert.ToInt32
(Request.QueryString["parcelID"]));
DataBind();
}

p.ParcelName returns the parcel name from the business
layer in string format. When I attempt to access
the .aspx page, the following error is generated:

CS0246: The type or namespace name 'p' could not be found

Your advice will be greatly appreciated.

-Andrew
 
You issue is one of scope. The object "p" is only in scope for that method.
In order to databind within the aspx page, which is a derived class from
your code-behind class, try moving the ParcelBusiness object to the class
level, and making it protected (so the derived class can see it).

[Add in Code-Behind]
protected ParcelBusiness p;

[Change In Page_Load]
p = new Parcel...etc...
 
Back
Top