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.-