Hi can someone please explain to me why I get the following error when I place the following code into a server control. It worked fine until I created the control???
Error: System.NullReferenceException: Object reference not set to an instance of an object.
Line 84: FirstParent = False
Line 85: Else
Line 86: Menu1.Items.Add(submenu1) ' Error
Line 87: submenu1 = New skmMenu.MenuItem(Mode)
Line 88: submenu1.CssClass = "highlighteditem"
Thanks!
...:: Code Behind ::..
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
loadMenu()
Menu1.CssClass = "menuStyle"
Menu1.Opacity = 100
Menu1.zIndex = 100
Menu1.Cursor = skmMenu.MouseCursor.Pointer
End If
End Sub
Sub loadMenu()
'Load Menu Items from Database
Dim Constr As String = ConfigurationSettings.AppSettings("strConn")
Dim cmd As String = "Select * FROM tblMenu ORDER BY ParentID,ChildID,GrandChildID"
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd, Constr)
Dim dt As New DataTable
da.fill(dt)
Dim i As Integer = dt.Rows.Count
Dim aa As Integer
Dim FirstParent As Boolean = True
Dim ChildGroup As Boolean = False
Dim parentID, childID, grandchildID As Integer
Dim Mode, mnuURL As String
Dim submenu1 As New skmMenu.MenuItem
Dim ChildMenu1 As New skmMenu.MenuItem
Dim ISParent, ISChild, newGrandChildGroup As Boolean
For aa = 0 To i - 1
parentID = dt.Rows(aa).Item(0)
childID = dt.Rows(aa).Item(1)
grandchildID = dt.Rows(aa).Item(2)
Mode = dt.Rows(aa).Item(3)
If Not IsDBNull(dt.Rows(aa).Item(4)) Then
mnuURL = (dt.Rows(aa).Item(4))
Else
mnuURL = ""
End If
If Trim(dt.Rows(aa).Item(4)) <> "N" Then
ISParent = False
ISChild = False
newGrandChildGroup = False
If childID = 0 And grandchildID = 0 Then ISParent = True
If childID > 0 And grandchildID > 0 Then ISChild = True
If childID > 0 And grandchildID = 0 Then newGrandChildGroup = True
If ISParent Then
If ChildGroup Then
submenu1.SubItems.Add(ChildMenu1)
ChildGroup = False
End If
If FirstParent Then
submenu1 = New skmMenu.MenuItem(Mode)
submenu1.CssClass = "highlighteditem"
FirstParent = False
Else
Menu1.Items.Add(submenu1)
submenu1 = New skmMenu.MenuItem(Mode)
submenu1.CssClass = "highlighteditem"
End If
End If
If ISChild Then
If ChildGroup And newGrandChildGroup Then
submenu1.SubItems.Add(ChildMenu1)
ChildGroup = False
End If
If Not ChildGroup Then submenu1.SubItems.Add(New skmMenu.MenuItem(Mode, mnuURL))
End If
If newGrandChildGroup Then
ChildMenu1 = New skmMenu.MenuItem(Mode)
ChildGroup = True
End If
If ChildGroup And Not newGrandChildGroup Then
ChildMenu1.SubItems.Add(New skmMenu.MenuItem(Mode, mnuURL))
End If
End If
Next aa
If ChildGroup Then
submenu1.SubItems.Add(ChildMenu1)
End If
Menu1.Items.Add(submenu1)
End Sub 1 1396
Don't worry! I worked out the problem!
Thanks
"Tim::.." wrote: Hi can someone please explain to me why I get the following error when I place the following code into a server control. It worked fine until I created the control???
Error: System.NullReferenceException: Object reference not set to an instance of an object.
Line 84: FirstParent = False Line 85: Else Line 86: Menu1.Items.Add(submenu1) ' Error Line 87: submenu1 = New skmMenu.MenuItem(Mode) Line 88: submenu1.CssClass = "highlighteditem"
Thanks!
..:: Code Behind ::.. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then loadMenu() Menu1.CssClass = "menuStyle" Menu1.Opacity = 100 Menu1.zIndex = 100 Menu1.Cursor = skmMenu.MouseCursor.Pointer End If End Sub
Sub loadMenu() 'Load Menu Items from Database Dim Constr As String = ConfigurationSettings.AppSettings("strConn") Dim cmd As String = "Select * FROM tblMenu ORDER BY ParentID,ChildID,GrandChildID" Dim da As SqlDataAdapter = New SqlDataAdapter(cmd, Constr) Dim dt As New DataTable da.fill(dt)
Dim i As Integer = dt.Rows.Count Dim aa As Integer Dim FirstParent As Boolean = True Dim ChildGroup As Boolean = False Dim parentID, childID, grandchildID As Integer Dim Mode, mnuURL As String Dim submenu1 As New skmMenu.MenuItem Dim ChildMenu1 As New skmMenu.MenuItem Dim ISParent, ISChild, newGrandChildGroup As Boolean
For aa = 0 To i - 1 parentID = dt.Rows(aa).Item(0) childID = dt.Rows(aa).Item(1) grandchildID = dt.Rows(aa).Item(2) Mode = dt.Rows(aa).Item(3) If Not IsDBNull(dt.Rows(aa).Item(4)) Then mnuURL = (dt.Rows(aa).Item(4)) Else mnuURL = "" End If If Trim(dt.Rows(aa).Item(4)) <> "N" Then ISParent = False ISChild = False newGrandChildGroup = False If childID = 0 And grandchildID = 0 Then ISParent = True If childID > 0 And grandchildID > 0 Then ISChild = True If childID > 0 And grandchildID = 0 Then newGrandChildGroup = True
If ISParent Then If ChildGroup Then submenu1.SubItems.Add(ChildMenu1) ChildGroup = False End If If FirstParent Then submenu1 = New skmMenu.MenuItem(Mode) submenu1.CssClass = "highlighteditem" FirstParent = False Else Menu1.Items.Add(submenu1) submenu1 = New skmMenu.MenuItem(Mode) submenu1.CssClass = "highlighteditem" End If End If If ISChild Then If ChildGroup And newGrandChildGroup Then submenu1.SubItems.Add(ChildMenu1) ChildGroup = False End If If Not ChildGroup Then submenu1.SubItems.Add(New skmMenu.MenuItem(Mode, mnuURL)) End If If newGrandChildGroup Then ChildMenu1 = New skmMenu.MenuItem(Mode) ChildGroup = True End If If ChildGroup And Not newGrandChildGroup Then ChildMenu1.SubItems.Add(New skmMenu.MenuItem(Mode, mnuURL)) End If End If Next aa
If ChildGroup Then submenu1.SubItems.Add(ChildMenu1) End If Menu1.Items.Add(submenu1)
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much...
|
by: Wolfgang Kaml |
last post by:
I am not sure if this is more of an expert question, but I am sure that they
are out there.
I'd like to setup a general application or bin directory on my Win2003.Net
Server that will hold some...
|
by: p |
last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also
have Crystal 9 pro on my development machine. The web app runs fine on my
dev machine but am having problems deploying....
|
by: JTrigger |
last post by:
When I compile my project using the IDE on a development machine it works
just fine. When I compile it on the server using csc.exe, I get the
following error when I try to bring it up in the web...
|
by: blash |
last post by:
Can someone help me? I really don't have a clue.
My company staff told me they often got such error: "Object reference
not set to an instance of an object." when they are in search result
page...
|
by: Patrick |
last post by:
I understand it is built in behaviour that if an ASP.NET's web.config is set
to:
<customErrors
mode="RemoteOnly"
/>
then I only get a detailed error message on screen when the ASP.NET...
|
by: Nathan Sokalski |
last post by:
When I view any page in my application a second time, I recieve the
following error:
System.Web.TraceContext.AddNewControl(String id, String parentId, String
type, Int32 viewStateSize) +313...
|
by: rushikesh.joshi |
last post by:
Hi All,
I have created my own WebControl and want to add it in my aspx page at
runtime.
it's compiling perfectly, but when i m going to execute, it gives me
error of "Object reference not set...
|
by: ollyb303 |
last post by:
Hi,
wasn't sure whether I should post this under .net, IIS or access, but I've plumped for .net!
I have a problem with an asp.net website which I am hosting on a windows server 2003 under IIS...
|
by: aboutjav.com |
last post by:
Hi,
I need some help. I am getting this error after I complete the asp.net
register control and click on the continue button. It crashed when it
tries to get
it calls this Profile property
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |