Re: Simple datalist question

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Tue, 19 Apr 2005 12:51:02 -0500, dinesh <dinesh@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I'm converting an app written using the pure .net framework from command
line, to Visual studio 2003. Having a problem with the datalist that wasnt
there before:


e:\inetpub\wwwroot\WebApplication2\winelist.aspx.cs(38): The type or
namespace name 'MyList' could not be found (are you missing a using directive
or an assembly reference?)


MyList.DataSource = productlist.gettheitems(color, category, year, region,
appellation, country);
MyList.DataBind();


What am I missing?

TIA
D


I assume you probably copied your aspx code to the aspx file in Visual Studio, and then moved your c# code from the new aspx to the code-behind? If so, one thing you're missing is that when you drop a control on a form (aspx), VS adds a field variable declaration to the code-behind for that control. So if I dropped a Literal control on my form, in my code-behind it adds:


class Page MyPage
{
....
	//this line is added
	protected System.Web.UI.WebControls.Literal ltlContent;
....
}

then you can access that control in your code-behind.

Remember the aspx file inherits from a code-behind file. So by doing this, when the aspx file is loaded, the variable declaration is inherited from the code-behind class, and .NET automatically associates the loaded control in the page to it..

So put a line similar to this one in your code-behind class for each server control, changing the type(s) to the corresponding control type...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
.



Relevant Pages

  • RE: FindControl() on ASP.NET UserControl Objects
    ... One more thing, Manish - ... I tried building an ASPX WITHOUT a code-behind and then, ... For declarative inclusion of control in the page, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: User Control Code-Behind
    ... Create a control with code behind ... Assuming that the ASPX page doesn't use a code-behind, ... events etc. of the user control in the ASPX page in this ... Now I decide to use a code-behind for the ASPX ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Panel Placement
    ... When an .aspx file includes the control from the .ascx file there is no ... control for the placement of the user control (panel) in the .aspx file. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Panel Placement
    ... This is true for .aspx file. ... This is not true for .ascx file. ... control for the placement of the user control (panel) in the .aspx file. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Accessing UserControls in ASPX code-behind pages
    ... Just like putting a label control called myLabel on the page. ... .ASPX page which has a code-behind .CS file. ... if I want to put a SomeUserControl on my ...
    (microsoft.public.dotnet.framework.aspnet)