F
Fossie
Hello,
I'm trying to streamline an app by converting inline code into a
functions.vb file in the App_Code folder but can't seem to work out
this error: The code worked fine in its "inline version".
BC30456: 'LinkCat_ItemDataBound' is not a member of 'ASP.default_aspx
Line 45: <aspataList id="LinkCat" RepeatColumns="2"
RepeatDirection="Horizontal" OnItemDataBound="LinkCat_ItemDataBound"
runat="server">
Many thanks in advance.
default.aspx
<%@ Page Language="VB" MasterPageFile="site.master" Debug="True"%>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<%@ import Namespace="System.Configuration" %>
<script runat="server">
'++++++++++++++++++++++++++++++++++++++++++++
'Handle the page load event
Sub Page_Load(Sender As Object, E As EventArgs)
dim Display_Category,Total_Link_Count,Display_Letter_Links
'Display all categories
Display_Category.Display_Category
'Call Total Link Count - get the number links
Total_Link_Count.Total_Link_Count
'Call risplay link name A to Z
Display_Letter_Links.Display_Letter_Links
Display_Letter_Links.lblletter.Text = "Link Name A-Z:"
End Sub
'++++++++++++++++++++++++++++++++++++++++++++
</script>
functions.vb (in App-Code)
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Namespace MyXD
Module myModule
'++++++++++++++++++++++++++++++++++++++++++++
'Declare public so it will accessible in all subs
Public strConnection
Public objConnection
Public objCommand
Public strSQL as string
Public iRandomLink as integer
Public strSubCatName as string
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Database connection string - Open database
Public Class DBconnect
Public Shared Sub DBconnect()
strConnection = ConfigurationSettings.AppSettings("MyXD")
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL, objConnection)
objConnection.Open()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Display all categories with count
Public Class Display_Category
Public Shared Sub Display_Category()
dim strSQL,lbltotalCat,LinkCat
strSQL = "SELECT *, (SELECT COUNT (*) FROM LINKS WHERE LINKS.CAT_ID =
CATEGORY.CAT_ID AND LINK_APPROVED = 1) AS REC_COUNT FROM CATEGORY ORDER
BY CAT_NAME ASC"
'Call Open database - connect to the database
DBconnect.DBconnect()
Dim LinkAdapter as New OledbDataAdapter(objCommand)
Dim dts as New DataSet()
LinkAdapter.Fill(dts, "CAT_ID")
lbltotalCat.Text = CStr(dts.Tables(0).Rows.Count) &
" categories"
LinkCat.DataSource = dts.Tables("CAT_ID").DefaultView
LinkCat.DataBind()
'Close database connection
objConnection.Close()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Show an Item in a Bound List - Display sub categories
Public Class LinkCat_ItemDataBound
Public Shared Sub LinkCat_ItemDataBound(sender As Object, e As
DataListItemEventArgs)
'First, make sure we're not dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header AND e.Item.ItemType <>
ListItemType.Footer then
Dim intCatID as integer
Dim strSQL2 as string
intCatID = DataBinder.Eval(e.Item.DataItem, "CAT_ID")
Dim subnamelabel As Label =
CType(e.Item.FindControl("lblsubname"), Label)
'SQL display details and rating value
strSQL2 = "SELECT * FROM SUBCATEGORY WHERE CAT_ID=" & intCatID
& " Order by SUB_NAME DESC"
Dim objDataReader as OledbDataReader
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL2, objConnection)
objConnection.Open()
objDataReader = objCommand.ExecuteReader()
'Read data
objDataReader.Read()
Dim intSID as integer = objDataReader("SUB_ID")
subnamelabel.text = subnamelabel.text & "<a class=""dt3"" title=""Go to
" & objDataReader("SUB_NAME") &" Sub-Category""
href=""pageview.aspx?tab=" & 1 & "&catid=" & intCatID & "&subid=" &
intSID & """>" & objDataReader("SUB_NAME") & "</a>"
objDataReader.Close()
objConnection.Close()
Dim intCatID2 as integer
Dim strSQL3 as string
intCatID2 = DataBinder.Eval(e.Item.DataItem, "CAT_ID")
Dim subnamelabel2 As Label =
CType(e.Item.FindControl("lblsubname2"), Label)
'SQL display details and rating value
strSQL3 = "SELECT * FROM SUBCATEGORY WHERE CAT_ID=" & intCatID2
& " Order by SUB_NAME ASC"
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL3, objConnection)
objConnection.Open()
objDataReader = objCommand.ExecuteReader()
'Read data
objDataReader.Read()
Dim intSID2 as integer = objDataReader("SUB_ID")
subnamelabel2.text = subnamelabel2.text & "<a class=""dt3"" title=""Go
to " & objDataReader("SUB_NAME") &" Sub-Category""
href=""pageview.aspx?tab=" & 1 & "&catid=" & intCatID2 & "&subid=" &
intSID2 & """>" & objDataReader("SUB_NAME") & "</a>..."
objDataReader.Close()
objConnection.Close()
End if
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Display the alphabetical letter listing in the footer
Public Class Display_Letter_Links
Public Shared Sub Display_Letter_Links()
Dim i as Integer,lblalphaletter
lblalphaletter.Text = string.empty
for i = 65 to 90
lblalphaletter.text = lblalphaletter.text & "<a
href=""pageview.aspx?tab=2&l=" & chr(i) & chr(34) & _
" class=""letter"" title="& chr(i) & ">" & chr(i) & "</a> "
next
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Count the total number of links
Public Class Total_Link_Count
Public Shared Sub Total_Link_Count()
dim lbltotalLinks
Dim CmdCount As New OleDbCommand("Select Count(LINK_ID) From
LINKS", New OleDbConnection(strConnection))
CmdCount.Connection.Open()
lbltotalLinks.Text = "There are " &
CmdCount.ExecuteScalar() & " links in "
CmdCount.Connection.Close()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
End Module
End Namespace
I'm trying to streamline an app by converting inline code into a
functions.vb file in the App_Code folder but can't seem to work out
this error: The code worked fine in its "inline version".
BC30456: 'LinkCat_ItemDataBound' is not a member of 'ASP.default_aspx
Line 45: <aspataList id="LinkCat" RepeatColumns="2"
RepeatDirection="Horizontal" OnItemDataBound="LinkCat_ItemDataBound"
runat="server">
Many thanks in advance.
default.aspx
<%@ Page Language="VB" MasterPageFile="site.master" Debug="True"%>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<%@ import Namespace="System.Configuration" %>
<script runat="server">
'++++++++++++++++++++++++++++++++++++++++++++
'Handle the page load event
Sub Page_Load(Sender As Object, E As EventArgs)
dim Display_Category,Total_Link_Count,Display_Letter_Links
'Display all categories
Display_Category.Display_Category
'Call Total Link Count - get the number links
Total_Link_Count.Total_Link_Count
'Call risplay link name A to Z
Display_Letter_Links.Display_Letter_Links
Display_Letter_Links.lblletter.Text = "Link Name A-Z:"
End Sub
'++++++++++++++++++++++++++++++++++++++++++++
</script>
functions.vb (in App-Code)
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Namespace MyXD
Module myModule
'++++++++++++++++++++++++++++++++++++++++++++
'Declare public so it will accessible in all subs
Public strConnection
Public objConnection
Public objCommand
Public strSQL as string
Public iRandomLink as integer
Public strSubCatName as string
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Database connection string - Open database
Public Class DBconnect
Public Shared Sub DBconnect()
strConnection = ConfigurationSettings.AppSettings("MyXD")
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL, objConnection)
objConnection.Open()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Display all categories with count
Public Class Display_Category
Public Shared Sub Display_Category()
dim strSQL,lbltotalCat,LinkCat
strSQL = "SELECT *, (SELECT COUNT (*) FROM LINKS WHERE LINKS.CAT_ID =
CATEGORY.CAT_ID AND LINK_APPROVED = 1) AS REC_COUNT FROM CATEGORY ORDER
BY CAT_NAME ASC"
'Call Open database - connect to the database
DBconnect.DBconnect()
Dim LinkAdapter as New OledbDataAdapter(objCommand)
Dim dts as New DataSet()
LinkAdapter.Fill(dts, "CAT_ID")
lbltotalCat.Text = CStr(dts.Tables(0).Rows.Count) &
" categories"
LinkCat.DataSource = dts.Tables("CAT_ID").DefaultView
LinkCat.DataBind()
'Close database connection
objConnection.Close()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Show an Item in a Bound List - Display sub categories
Public Class LinkCat_ItemDataBound
Public Shared Sub LinkCat_ItemDataBound(sender As Object, e As
DataListItemEventArgs)
'First, make sure we're not dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header AND e.Item.ItemType <>
ListItemType.Footer then
Dim intCatID as integer
Dim strSQL2 as string
intCatID = DataBinder.Eval(e.Item.DataItem, "CAT_ID")
Dim subnamelabel As Label =
CType(e.Item.FindControl("lblsubname"), Label)
'SQL display details and rating value
strSQL2 = "SELECT * FROM SUBCATEGORY WHERE CAT_ID=" & intCatID
& " Order by SUB_NAME DESC"
Dim objDataReader as OledbDataReader
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL2, objConnection)
objConnection.Open()
objDataReader = objCommand.ExecuteReader()
'Read data
objDataReader.Read()
Dim intSID as integer = objDataReader("SUB_ID")
subnamelabel.text = subnamelabel.text & "<a class=""dt3"" title=""Go to
" & objDataReader("SUB_NAME") &" Sub-Category""
href=""pageview.aspx?tab=" & 1 & "&catid=" & intCatID & "&subid=" &
intSID & """>" & objDataReader("SUB_NAME") & "</a>"
objDataReader.Close()
objConnection.Close()
Dim intCatID2 as integer
Dim strSQL3 as string
intCatID2 = DataBinder.Eval(e.Item.DataItem, "CAT_ID")
Dim subnamelabel2 As Label =
CType(e.Item.FindControl("lblsubname2"), Label)
'SQL display details and rating value
strSQL3 = "SELECT * FROM SUBCATEGORY WHERE CAT_ID=" & intCatID2
& " Order by SUB_NAME ASC"
objConnection = New OledbConnection(strConnection)
objCommand = New OledbCommand(strSQL3, objConnection)
objConnection.Open()
objDataReader = objCommand.ExecuteReader()
'Read data
objDataReader.Read()
Dim intSID2 as integer = objDataReader("SUB_ID")
subnamelabel2.text = subnamelabel2.text & "<a class=""dt3"" title=""Go
to " & objDataReader("SUB_NAME") &" Sub-Category""
href=""pageview.aspx?tab=" & 1 & "&catid=" & intCatID2 & "&subid=" &
intSID2 & """>" & objDataReader("SUB_NAME") & "</a>..."
objDataReader.Close()
objConnection.Close()
End if
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Display the alphabetical letter listing in the footer
Public Class Display_Letter_Links
Public Shared Sub Display_Letter_Links()
Dim i as Integer,lblalphaletter
lblalphaletter.Text = string.empty
for i = 65 to 90
lblalphaletter.text = lblalphaletter.text & "<a
href=""pageview.aspx?tab=2&l=" & chr(i) & chr(34) & _
" class=""letter"" title="& chr(i) & ">" & chr(i) & "</a> "
next
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++
'Count the total number of links
Public Class Total_Link_Count
Public Shared Sub Total_Link_Count()
dim lbltotalLinks
Dim CmdCount As New OleDbCommand("Select Count(LINK_ID) From
LINKS", New OleDbConnection(strConnection))
CmdCount.Connection.Open()
lbltotalLinks.Text = "There are " &
CmdCount.ExecuteScalar() & " links in "
CmdCount.Connection.Close()
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++
End Module
End Namespace