Subject: Name 'CAM' is not declared.
Posted By: belmin45 Post Date: 5/14/2008 4:25:09 AM
can you helped me in this code...i am only a beginner of asp.net but seems it always like this.i buy two books of wrox but the sample is always not compiling..


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'CAM' is not declared.

Source Error:


Line 92:                 <asp:TemplateColumn SortExpression="Author" HeaderText="Author">
Line 93:                     <ItemTemplate>
Line 94:                         <asp:Label id="Label1" runat="server"> <%# CAM.Formatting.MyCstr(Container.DataItem("Author"), True, False) %> </asp:Label>
Line 95:                     </ItemTemplate>
Line 96:                 </asp:TemplateColumn>


Source File: C:\Inetpub\wwwroot\GuestbookKO\NewFile.aspx    Line: 94
this is the main code:




<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="CAM" TagName="Menu" Src="header.ascx" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)
    
    
    
        If Not Page.IsPostBack Then
    
            ' Databind the data grid on the first request only
            ' (on postback, rebind only in paging and sorting commands)
    
            BindGrid()
    
        End If
    
    End Sub
    
    Property SortField() As String
    
        Get
            Dim o As Object = ViewState("SortField")
            If o Is Nothing Then
                Return String.Empty
            End If
            Return CStr(o)
        End Get
    
        Set(ByVal Value As String)
            ViewState("SortField") = Value
        End Set
    
    End Property
      Sub DataGrid_Page(Sender As Object, e As DataGridPageChangedEventArgs)
    
            DataGrid1.CurrentPageIndex = e.NewPageIndex
            BindGrid()
    
        End Sub
    
        Sub DataGrid_Sort(Sender As Object, e As DataGridSortCommandEventArgs)
    
            DataGrid1.CurrentPageIndex = 0
            SortField = e.SortExpression
            BindGrid()
    
        End Sub
    
    
    Sub BindGrid()
    
    
    
        Dim CommandText As String
    
        ' TODO: update the CommandText value for your application
        If SortField = String.Empty Then
            CommandText = "select Author, Subject, Message, PostedDate from GuestBookEntries order by PostedDate desc"
        Else
            CommandText = "select Author, Subject, Message, PostedDate from GuestBookEntries order by " & SortField
        End If
    
        Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("CAM"))
        Dim myCommand As New SqlDataAdapter(CommandText, myConnection)
    
        Dim ds As New DataSet()
        myCommand.Fill(ds)
    
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
    
    End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
    <h2>
        <CAM:Menu id="Menu" title="Guest Book" runat="server"></CAM:Menu>
    </h2>
    <hr size="1" />
    <form runat="server">
        <asp:datagrid id="DataGrid1" runat="server" OnSortCommand="DataGrid_Sort" OnPageIndexChanged="DataGrid_Page" width="80%" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" PageSize="6" ForeColor="Black" BackColor="White" CellPadding="3" GridLines="None" CellSpacing="1">
            <HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
            <PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle>
            <ItemStyle backcolor="#DEDFDE"></ItemStyle>
            <Columns>
                <asp:TemplateColumn SortExpression="Author" HeaderText="Author">
                    <ItemTemplate>
                        <asp:Label id="Label1" runat="server"> <%# CAM.Formatting.MyCstr(Container.DataItem("Author"), True, False) %> </asp:Label>
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns>
        </asp:datagrid>
    </form>
</body>
</html>


belmin
Reply By: virendar23 Reply Date: 5/27/2008 1:56:50 AM
Web Config may be missing the entry for this control . Need to add the contol in control tag in web config.

Check It out
Reply By: Imar Reply Date: 5/27/2008 2:13:32 AM
I don't think this has to do with existing examples from books, but with your own code. Take a look at this:

CAM.Formatting.MyCstr

Where is CAM defined? Where is Formatting defined? What makes you believe this should work? I don't see any other reference to Formatting than the one in the code generating an error.

If you explain a bit more about your code / setup, maybe we can offer something useful.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Go to topic 71664

Return to index page 1