Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 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 March 22nd, 2004, 02:01 PM
Authorized User
 
Join Date: Sep 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cjcd
Default This time, Code Behind

Hello, I posted earlier about a datagrid problem, I was told to try the repeater and I did, it worked fantastic. Now I want to move my code and separate it from what I've done (Code Behind file), when it's all in one page, it works beautifully, when I separate the code to a .vb file, it doesn't.

Here's the whole thing:

<%@ Page Language="VB" runat="server" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script runat="server">

    Sub Page_Load()
        Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
          strConnection += "Data Source=G:\Projects 2\DotNet Guestbook\data\guestbook.mdb"
        Dim strSQL as String = "SELECT * FROM Comments"
        Dim objDataSet as new DataSet()

        Dim objConnection as New OledbConnection(strConnection)
        Dim objAdapter as new OledbDataAdapter(strSQL, objConnection)

        objAdapter.Fill(objDataSet, "Comments")

        Dim objDataView as New DataView(objDataSet.Tables("Comments"))

      DataGrid1.DataSource = objDataView
      DataGrid1.DataBind()
    End Sub

</script>
<html>
<head>
    <title>Data Grid Control example</title>
</head>
<body>
    <p>
        <asp:Repeater id="datagrid1" runat="server">
            <itemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "name") %> - <%# DataBinder.Eval(Container.DataItem, "comment") %>
                <br />
            </itemTemplate>
        </asp:Repeater>
    </p>
    <p>
        <asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="test2dataadd.aspx">Add a Comment</asp:HyperLink>
    </p>
</body>
</html>

This works fine, here's the pice that I took to a vb file:

Imports System
Imports System.Data
Imports System.Data.Oledb

Public Class guestbook

    Public Sub Page_Load()

        Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
          strConnection += "Data Source=G:\Projects 2\DotNet Guestbook\data\guestbook.mdb"
        Dim strSQL as String = "SELECT * FROM Comments"
        Dim objDataSet as new DataSet()

        Dim objConnection as New OledbConnection(strConnection)
        Dim objAdapter as new OledbDataAdapter(strSQL, objConnection)

        objAdapter.Fill(objDataSet, "Comments")

        Dim objDataView as New DataView(objDataSet.Tables("Comments"))

      DataGrid1.DataSource = objDataView
      DataGrid1.DataBind()

    End Sub

End Class

The error it gives me is that the datagrid is not declared.

DO you see a possible solution, what's the protocol to take out the working code and put it on a code behind file?

Thanks.-

 
Old October 5th, 2004, 11:33 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to add a declaration of the datagrid name

 
Old October 5th, 2004, 12:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You need to add following attributes to the @Page declaration:

CodeBehind - Name of the .vb file
Inherits - The fully-quantified class name to inherit (including class name of .vb file)

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet/XSD files instead of Run Time Code aesalazar Visual Basic 2005 Basics 3 May 25th, 2007 11:57 AM
Getting a Run-Time Error with this code.. Smythe Access VBA 2 May 28th, 2006 07:06 PM
How do I execute a code every X period of time? Master_D PHP How-To 3 June 8th, 2004 10:10 AM
Calling code multiple time???? Louisa VB.NET 2002/2003 Basics 11 May 14th, 2004 07:22 AM
Run-time code execution module0000 Beginning VB 6 1 June 20th, 2003 04:19 AM





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