Making Labels visible at runtime

kdevine

New member
Joined
Feb 3, 2005
Messages
2
Programming Experience
5-10
I am trying to write an aspx page that can set some visibility of a control based on whether it has data in it or not. Here is a code snippet:

VB.NET:
[size=2]
Lbl = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Label

Lbl = [/size][size=2][color=#0000ff]CType[/color][/size][size=2]([/size][size=2][color=#0000ff]Me[/color][/size][size=2].FindControl("lblGroup" & i), Label)

[/size][size=2][color=#0000ff]If[/color][/size][size=2] [/size][size=2][color=#0000ff]Not[/color][/size][size=2] IsDBNull(dr("GroupName")) [/size][size=2][color=#0000ff]Then[/color][/size][size=2] Lbl.Text = dr("GroupName") & ":"

Lbl.Visible = [/size][size=2][color=#0000ff]True

[/color][/size]

Any thoughts on why this gives a "System.NullReferenceException: Object reference not set to an instance of an object."

Thanks,
Kevin Devine
Network Systems Administrator
Euclid Public Library
kdevine@euclidlibraryNOSPAM.org
 
Ok, I solved this with some more tinkering around. It seems that dr("GroupName") was not getting anything because of a typo in the SQL (it was returning a recordset, just not exactly the one I wanted) and that caused the issue.
 
Back
Top