Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2008, 04:58 AM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default variable not defined error?

Hi
Bellow is the code could someone help me why i am getting the forllowing error: Name 'NCategory' is not declared.


Many thanks
Sheraz


  <asp:Repeater ID="RPTMonth" runat ="server" >
            <ItemTemplate>
                <% Dim NCategory As String = Request.QueryString("Category")
                    Dim NYear As String = Request.QueryString("Year")
                %>
                    <li><a href ='http://localhost/archivednews.aspx?Category=<%=NCategory%>&Month=<% #MonthNumber(Container.DataItem)%>&Year=<%=NYear%> &Page=1'><%#Container.DataItem%> - <%=NYear%> - <%#GetRichTextKeywords(NCategory)%></a></li>

            </ItemTemplate>

        </asp:Repeater>
 
Old April 1st, 2008, 05:48 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I suspect this has to do with the way you are using inline code and the data binding expression.

The way you are doing this is rather awkward and kind of defeats the intent of code behind. You are creating 2 strings in each iteration of your repeater. Why? The value for each comes from the query string so will clearly never change from item to item, so they should be in the code behind. Modify them as 'Protected' and your inline page code can see them.

One thing you might try is to change the 'Response.Write' shortcut inline snippets to data binding snippets:

<a href ='http://localhost/archivednews.aspx?Category=<%#NCategory%>&Month=<% #MonthNumber(Container.DataItem)%>&Year=<%#NYear%> &Page=1'><%#Container.DataItem%> - <%#NYear%> - <%#GetRichTextKeywords(NCategory)%></a>


-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting variable to user defined type mantle51 SQL Server 2000 3 August 10th, 2007 03:52 AM
Appl-defined or Object-defined error 1004 chp Excel VBA 3 April 4th, 2006 08:12 AM
Compile Error: Variable not defined Fin Excel VBA 0 February 1st, 2006 01:45 PM
Compile error-variable not defined tmiller1 VB Databases Basics 1 February 15th, 2005 04:15 PM
Application-defined or object-defined error James Excel VBA 1 August 12th, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.