Why am I getting "RadGrid1 is not declared" ?

1 Answer 113 Views
Grid
Ross
Top achievements
Rank 1
Iron
Ross asked on 09 May 2023, 02:17 PM

Why am I getting "RadGrid1 is not declared" ?

Running VS2019, Telerik version: 2022.3.1109.45 



ASPX page
---------------------------------------------------------------------------------------------------------------------------------------

<%@ Page Language="vb" AutoEventWireup="true" CodeFile="PriorityLists.aspx.vb" Inherits="WebApp.TDAPInterface.PriorityLists" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Priority Lists</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #demo {
            width: 891px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="false" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <telerik:RadFormDecorator RenderMode="Lightweight" runat="server" DecorationZoneID="demo" EnableRoundedCorners="false" DecoratedControls="All" />
<div id="demo" class="demo-container no-bg">
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" DataSourceID="TDAPConnectionString"
AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
AllowAutomaticDeletes="True" AllowSorting="True"
OnItemInserted="RadGrid1_ItemInserted" OnPreRender="RadGrid1_PreRender" OnInsertCommand="RadGrid1_InsertCommand" AutoGenerateEditColumn="True" Width="893px" OnItemDataBound="RadGrid1_ItemDataBound" Skin="Office2010Black">
<PagerStyle Mode="NextPrevAndNumeric" />
<GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>

<ClientSettings>
                <Selecting AllowRowSelect="True" />
            </ClientSettings>

<MasterTableView DataSourceID="TDAPConnectionString" AutoGenerateColumns="False"
DataKeyNames="PriorityListId" CommandItemDisplay="Top">

<CommandItemTemplate>
<asp:Button ID="Button1" Text="Display Prioritizion for Selected Row" runat="server" OnClick="Button1_Click" CssClass="rgAdd">
</asp:Button>

<asp:Button ID="btnAdd" Text="Add New Priority List" runat="server" CommandName="InitInsert" CssClass="rgAdd" />
</CommandItemTemplate>   

<RowIndicatorColumn ShowNoSortIcon="False" Visible="False">
    <HeaderStyle Width="41px" />
                </RowIndicatorColumn>

<ExpandCollapseColumn ShowNoSortIcon="False">
    <HeaderStyle Width="41px" />
                </ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="PriorityListId" HeaderText="Priority List Id" SortExpression="PriorityListId"
UniqueName="PriorityListId" DataType="System.Int32" FilterControlAltText="Filter PriorityListId column" ReadOnly="True">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PriorityTitle" HeaderText="Priority Title" SortExpression="PriorityTitle"
UniqueName="PriorityTitle" FilterControlAltText="Filter PriorityTitle column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SiteIdNumber" HeaderText="Site IdNumber" SortExpression="SiteIdNumber"
UniqueName="SiteIdNumber" FilterControlAltText="Filter SiteIdNumber column" Visible="False">
</telerik:GridBoundColumn>
</Columns>

<EditFormSettings>
<EditColumn ShowNoSortIcon="False" UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
</EditFormSettings>
</MasterTableView>

<FilterMenu RenderMode="Lightweight"></FilterMenu>

<HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
</telerik:RadGrid>
    <asp:SqlDataSource ID="TDAPConnectionString" runat="server" ConnectionString="<%$ ConnectionStrings:TDAPConnectionString %>" DeleteCommand="DELETE FROM [Submission_PriorityLists] WHERE [PriorityListId] = @PriorityListId" InsertCommand="INSERT INTO [Submission_PriorityLists] ([PriorityTitle], [SiteIdNumber]) VALUES (@PriorityTitle, @SiteIdNumber)" SelectCommand="SELECT * FROM [Submission_PriorityLists] ORDER BY [PriorityTitle]" UpdateCommand="UPDATE [Submission_PriorityLists] SET [PriorityTitle] = @PriorityTitle, [SiteIdNumber] = @SiteIdNumber WHERE [PriorityListId] = @PriorityListId">
            <DeleteParameters>
                <asp:Parameter Name="PriorityListId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="PriorityTitle" Type="String" />
                <asp:Parameter Name="SiteIdNumber" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="PriorityTitle" Type="String" />
                <asp:Parameter Name="SiteIdNumber" Type="String" />
                <asp:Parameter Name="PriorityListId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
</div>
    </form>
</body>
</html>


VB Codebehind
------------------------------------------------------------------------------------------------------------------------------------------

Imports System
Imports System.Collections
Imports System.Web.UI
Imports Telerik.Web.UI
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Data.Common
Imports System.Linq
Imports System.Text
Imports System.Reflection
Imports System.Data.SqlClient


Namespace TDAPInterface

    Partial Class PriorityLists
        Inherits System.Web.UI.Page

        Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
            If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
                If Not (TypeOf e.Item Is GridEditFormInsertItem) Then
                    Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
                    Dim manager As GridEditManager = item.EditManager
                    Dim editor As GridTextBoxColumnEditor = TryCast(manager.GetColumnEditor("PriorityListId"), GridTextBoxColumnEditor)
                    editor.TextBoxControl.Enabled = False
                End If
            End If
        End Sub

        Protected Sub RadGrid1_ItemInserted(source As Object, e As GridInsertedEventArgs) Handles RadGrid1.ItemInserted

            If e.Exception IsNot Nothing Then

                e.ExceptionHandled = True

                SetMessage("Priority List cannot be inserted. Reason: " + e.Exception.Message)
            Else
                SetMessage("New Priority List is inserted!")
            End If
        End Sub

        Private Sub DisplayMessage(text As String)
            RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text)))
        End Sub

        Private Sub SetMessage(message As String)
            gridMessage = message
        End Sub

        Private gridMessage As String = Nothing

        Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
            RadGrid1.MasterTableView.GetColumn("PriorityListId").Visible = False
            RadGrid1.Rebind()

            If Not String.IsNullOrEmpty(gridMessage) Then
                DisplayMessage(gridMessage)
            End If
        End Sub

        Protected Sub RadGrid1_InsertCommand(sender As Object, e As GridCommandEventArgs)
            If TypeOf e.Item Is GridEditableItem Then
                Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
                'here editedItem.SavedOldValues will be the dictionary which holds the
                'predefined values

                'Prepare new dictionary object
                Dim newValues As New Hashtable()
                'the newValues instance is the new collection of key -> value pairs
                'with the updated ny the user data
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)
            End If
        End Sub

        Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
            If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
                Dim eitem As GridEditableItem = CType(e.Item, GridEditableItem)
                eitem("SiteIdNumber").Visible = False    ' for making the cell invisible during editing
                eitem("SiteIdNumber").Parent.Visible = False ' for making its label also invisible

            End If
        End Sub

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim id As String = "0"
            Dim dataItem As GridDataItem
            For Each dataItem In RadGrid1.SelectedItems
                Dim index As Integer = dataItem.ItemIndex ' Get Row Index
                id = dataItem.GetDataKeyValue("PriorityListId").ToString() 'Accessing the datakey value
            Next
            If id = "0" Then
                SetMessage("Select a row!")
            End If
        End Sub

    End Class
End Namespace

1 Answer, 1 is accepted

Sort by
0
Ross
Top achievements
Rank 1
Iron
answered on 09 May 2023, 02:28 PM
In the ASPX file the "CodeFile" needs to be "CodeBehind" in a Webapp. This fixed the issue.
Rumen
Telerik team
commented on 10 May 2023, 09:25 AM

I am glad that you find the solution! Indeed, CodeFile is used for ASP.NET Web Forms Site projects, while CodeBehind is linked to ASP.NET Web Forms Application projects.

For anyone who wants to learn more, I would suggest the following SO discussion: https://stackoverflow.com/questions/73022/codefile-vs-codebehind


Tags
Grid
Asked by
Ross
Top achievements
Rank 1
Iron
Answers by
Ross
Top achievements
Rank 1
Iron
Share this question
or