473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XML fed Treeview - NULL Reference Exception

Hi folks,

A bizarre problem I am having.

I have a treeview which is bound to an XmlDataSource. The
XMLDataSource.Data property is set to the result of a function that
generates an XML document from a SQL Query. The problem is that the
Treeview renders correctly and expands with the appropriate hierarchy
but clicking anything but the very top node gives me a NULL Reference
Exception. I haven't even got to the stage of doing anything with the
tree apart from populate it, so there is no other code involved at
present.

Below is the code behind, the stored procedure, the XML document
generated by the procedure and the source view extract of the treeview
control
CODE BEHIND:

protected void Page_Load(object sender, EventArgs e) {
dsXmlContent.Data = GetXmlDoc().OuterXml;
}

protected XmlDocument GetXmlDoc() {
SqlConnection cn = new SqlConnection(@"data source=server;
database=database; user id=user; password=password");
SqlCommand cmd = new SqlCommand("procContent_GetContentMap", cn);
cn.Open();
XmlReader xr = cmd.ExecuteXmlReader();
XmlDocument doc = new XmlDocument();
doc.Load(xr);

xr.Close();
cn.Close();

return doc;

}

STORED PROCEDURE

Create PROCEDURE [dbo].[procContent_GetContentMap]

AS
BEGIN
SET NOCOUNT ON;

select
1 tag,
null parent,
null [Section!1!Section],
null [Sections!2!SectionID],
null [Sections!2!SectionName],
NULL [Pages!3!PageID],
NULL [Pages!3!PageName],
NULL [Contents!4!ContentID],
NULL [Contents!4!Html]

union all

select
2 tag,
1 parent,
null,
ID,
SectionName,
NULL,
NULL,
NULL,
NULL

from
Section

union all

select
3,
2,
null,
Section.ID,
null,
Page.ID,
Page.PageName,
NULL,
NULL

from
Section, Page

where
Section.ID = Page.SectionID

union all

select
4,
3,
null,
Section.ID,
null,
Page.ID,
null,
[Content].ID,
[Content].Html

from Section, Page, [Content]

where Section.ID = Page.SectionID
and Page.ID = [Content].PageID

order by [Section!1!Section], [Sections!2!SectionID],
[Pages!3!PageID], [Contents!4!ContentID]

for xml explicit

end

GENERATED XML DOCUMENT

<Section>
<Sections SectionID="1" SectionName="Test Section 1">
<Pages PageID="1" PageName="Section 1 Page 1">
<Contents ContentID="1" Html="Section 1 Page 1 content" />
</Pages>
<Pages PageID="2" PageName="Section 1 Page 2">
<Contents ContentID="2" Html="Section 1 Page 2 content" />
</Pages>
</Sections>
<Sections SectionID="2" SectionName="Test Section 2">
<Pages PageID="3" PageName="Section 2 Page 1">
<Contents ContentID="3" Html="Section 2 Page 1 content" />
</Pages>
<Pages PageID="4" PageName="Section 2 Page 2">
<Contents ContentID="4" Html="Section 2 Page 2 content" />
</Pages>
</Sections>
</Section>

SOURCE EXTRACT OF THE TREEVIEW CONTROL

<asp:TreeView ID="tvNav" runat="server" Style="position: relative"
PathSeparator="." DataSourceID="dsXmlContent" ExpandDepth="0"
ImageSet="XPFileExplorer" NodeIndent="15">
<DataBindings>
<asp:TreeNodeBinding DataMember="Sections" ValueField="SectionID"
TextField="SectionName" />
<asp:TreeNodeBinding DataMember="Pages" ValueField="PageID"
TextField="PageName" />
<asp:TreeNodeBinding DataMember="Contents" ValueField="ContentID"
TextField="Html" />
</DataBindings>
</asp:TreeView>

Any help greatly appreciated

Simon

Oct 23 '06 #1
2 2579
Just realised that the stack trace would be useful.

STACK TRACE

[NullReferenceException: Object reference not set to an instance of an
object.]
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) +39
System.Xml.XmlDocument.Load(XmlReader reader) +159

System.Web.UI.WebControls.XmlDataSource.PopulateXm lDocument(XmlDocument
document, CacheDependency& dataCacheDependency, CacheDependency&
transformCacheDependency) +388
System.Web.UI.WebControls.XmlDataSource.GetXmlDocu ment() +206
System.Web.UI.WebControls.XmlHierarchicalDataSourc eView.Select() +42
System.Web.UI.WebControls.TreeView.DataBindNode(Tr eeNode node) +477
System.Web.UI.WebControls.TreeView.PopulateNode(Tr eeNode node) +44
System.Web.UI.WebControls.TreeView.LoadPostData(St ring postDataKey,
NameValueCollection postCollection) +972

System.Web.UI.WebControls.TreeView.System.Web.UI.I PostBackDataHandler.LoadPostData(String
postDataKey, NameValueCollection postCollection) +36
System.Web.UI.Page.ProcessPostData(NameValueCollec tion postData,
Boolean fBeforeLoad) +897
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2549

Oct 23 '06 #2
Required a databind call in code behind. Now I have a bizarre collapse
problem but I'll sort that out me thinks :)

Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: meh | last post by:
I need to be able to persist a treeView to disk. I would like to save the node text, tag, image and selected image. I have done this using vb but I cant seem to translate from vb to vc#. Can ne1...
0
by: meh | last post by:
Still have not been able to convert this. More importently.....Is this sample going about it the right way??? tia meh Here is the vb code.........I keep looking at older vb.net projects to...
4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
0
by: MarkD | last post by:
I have an ASP.NET (VB.NET) application that calls all VB6 COM DLL via Interop. The DLL uses functionality contained in a Custom OCX Control (Also VB6) that in turn contains a standard TreeView...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
1
by: aaronh64 | last post by:
I'm trying to bind to the ASP.NET TreeView control and utilize the PopulateOnDemand functionality. However, I am receiving the following (very confusing) error: "PopulateOnDemand only supported...
0
by: selvakumari | last post by:
I am populating a treeview in c# from XmlFile, and i have implemented a multiselection in that treeview by overriding treeview select events when ctrl or shift is pressed, which was written a...
0
by: Selva Kumari Padmanabhan | last post by:
hi, i am a new to c#, i hav 4months experience in C#, I am populating a treeview in c# from XmlFile, and i have implemented a multiselection in that treeview by overriding treeview select...
2
by: Selva Kumari Padmanabhan | last post by:
hi, i am a new to c#, i hav 4months experience in C#, I am populating a treeview in c# from XmlFile, and i have implemented a multiselection in that treeview by overriding treeview select...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.