Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NULL issue

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
I have 2 controls inside a form

<asp:DropDownList id="MyDDL" runat="server" OnSelectedIndexChanged="DoStuff()">
and
<asp:treeview id="MyTree" runat="server" />

So changing my dropdownlist value OR click on a node in my tree can submit my form.

I have a line in my Page_Load() that accesses

MyTree.SelectedNode.Parent.Text

Obviously when the form is submitted via a click on a node in the tree this works fine but if it hits this line because of a submit by selecting a dropdown list value this line throws an error:


System.NullReferenceException: Object reference not set to an instance of an object


I can't seem to evaluate my expression to NULL in order to handle this.

If(MyTree.SelectedNode.Parent.Text Is Nothing)Then
.... ' does not work
End if

If(String.IsNullOrEmpty(MyTree.SelectedNode.Parent.Text))Then
.... ' does not work
End if

DBNull is for Datasets, how can I evaluate the expression to grab the NULL. I would like to be able to do this without Try/Catch for now

Thanks
 
Is it that the MyTree.SelectedNode itself is null, and that's what you need to trap? Since there was no click on the tree, there's no selected node set?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top