S
Simon Rigby
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
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