dataGrid is undefined in codebehind page?

G

Guest

I have a simple aspx page called type with a datagrid/w id=dGrdTyp
My code behind page is not reconizing the control on the aspx page.
Visualstudio.Net flaggs the dgrdTyp as undefined. Any Help? I'm a little new
to aspx in Visual Studio.Net
code follows:
THANKS!!!!
kes
Type.aspx.....
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="type.aspx.vb"
Inherits="damarstone.type"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>type</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<asp:Label id="lblUser" runat="server" Width="176px" Height="16px"
Font-Size="Smaller">Action</asp:Label><br>
<asp:Label id="lblStatus" runat="server" Width="202px" Height="8px"
Font-Size="Smaller">User Not Logged In</asp:Label><br>
<form id="Form1" method="post" runat="server">
<asp:LinkButton id="lnkToHome" style=""
runat="server">Home</asp:LinkButton>
<asp:DataGrid
ID="dGrdTyp"
AutoGenerateColumns="false"
ShowFooter="True"
Runat="server"
EnableViewState="false">
<columns>
<asp:HyperLinkColumn DataNavigateUrlField="typID"
DataNavigateUrlFormatString="Slabs.aspx?TypID={0}" DataTextField="TypName"
Headertext="Select Stone" runat="server" ID="Hyperlinkcolumn1"
NAME="Hyperlinkcolumn1"/>
</columns>

</asp:DataGrid>
</form>
</body>
</HTML>
type.aspx.vb.....

Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class type
Inherits Page
Public thsSitePath As String
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblUser As System.Web.UI.WebControls.Label
Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
Protected WithEvents lnkToHome As System.Web.UI.WebControls.LinkButton

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call Get_Location()
lblStatus.Text = thsSitePath & "kurt"
End Sub
Private Sub Get_Location()
Dim thsUri As Uri
Dim thsHost As String


thsUri = Request.Url
thsHost = thsUri.Host
If (thsHost = "www.damarstone.com") Then
thsSitePath = "c:\websites\damar\"
Else
thsSitePath = "e:\websites\damarstone\"
End If
End Sub
Private Sub BindDataGrid()
Dim conTyp As OleDbConnection
Dim cmdSelectTyp As OleDbCommand
Dim dtrTyp As OleDbDataReader
lnkToHome.Text = "me"
conTyp = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
Source=" & thsSitePath & "db\damarstone.mdb")
cmdSelectTyp = New OleDbCommand("SELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.ExecuteReader()

dGrdTyp.DataSource = dtrTyp
dGrdTyp.DataBind()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
 
S

Steve C. Orr [MVP, MCSD]

For some reason the datagrid is not declared in your codebehind. Usually
this happens automatically, but if you need to you can add it manually. Put
it along with the similar declarations in your code behind.
Protected WithEvents dGrdTyp As System.Web.UI.WebControls.DataGrid
 
M

Mike Ryan

Hi Kurt,

It looks like you need to declare the grid variable in the codebehind.
Check out how your labels are declared as a guide:

Protected WithEvents lblUser As System.Web.UI.WebControls.Label

- Mike
 
F

Francois

It sometimes happen to me. What i do is I "force" Visual Studio to
re-anallyze the control existing in the aspx file by switching from "design
view" to "code view". After that your datagrid should be declared in the
code behind.

Francois.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top