This is a migrated thread and some comments may be shown as answers.

About to bind the data from sql server uisng XMLDocuments

0 Answers 78 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Nilesh
Top achievements
Rank 1
Nilesh asked on 27 Jul 2008, 10:53 AM
Hi, I want to bind the radTreeview control with the sqlServer 2005 with having field learningTrack as XML Data type.

I want to bind only that coloumn to the treeview control using XMLDocuments class in asp.net 3.5 and c#.net 3.5. I have following code for binding for RadTreeView control.

I need Help for Binding the RadTreeView control.
***********************************************
Learningtrack.aspx
***********************************************
<div style="width:750px; margin-bottom:25px; margin-left:25px; margin-right:25px; margin-top:75px; padding:25px; height: 600px;">
   <div style="float:left; width:400px;">
   <div style="margin-left:10px">
    <asp:Label ID="TitleLabel" runat="server" ></asp:Label>
    <asp:Literal ID="VideoLiteral" runat="server"></asp:Literal>
   </div>
   <br />
   <div style="margin-left:10px">
   <asp:Label ID="ObjectiveLabel" Text="Objectives" runat="server"></asp:Label>
   <br />
   <telerik:radtextbox runat="server" Rows="5" Skin="Vista" TextMode="MultiLine"
           Width="325px" ID="ObjectiveTextBox"
           InvalidStyleDuration="100" LabelCssClass="radLabelCss_Vista"></telerik:radtextbox>
   </div>
   </div>
   <div style="float:right; width:300px;">
    <asp:TreeView ID="LearningTrackAndLessoinTreeView" runat="server" ImageSet="Arrows" OnTreeNodeDataBound="LearningTrackAndLessoinTreeView_TreeNodeDataBound">
        <ParentNodeStyle Font-Bold="False" />
        <HoverNodeStyle
            Font-Underline="True" ForeColor="#5555DD" />
        <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px"
            VerticalPadding="0px" ForeColor="#5555DD" />
        <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
            HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
    </asp:TreeView>
    <asp:XmlDataSource ID="LearningTrackAndLessionsXmlDataSource" runat="server"></asp:XmlDataSource>
    </div>
    </div>
***********************************************
Learningtrack.aspx.cs
***********************************************
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ACS;
using Deklarit;
using System.Xml;
using System.Xml.XPath;


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
                    BindLearningTrackLessonsAndTopics(LearningTrackName);
          }
        }
   

    protected void LearningTrackAndLessoinTreeView_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        TreeNode LearningTrackNode = (TreeNode)e.Node;
        XmlNode LearningTrackXMLNode = (XmlNode)e.Node.DataItem;
      
            if (LearningTrackXMLNode.NodeType == XmlNodeType.Element)
            {
                if (LearningTrackXMLNode.Attributes != null)
                {
                    for (int i = 2; i < LearningTrackXMLNode.Attributes.Count; i++)
                    {
                        TreeNode LearningLession = new TreeNode(LearningTrackXMLNode.Attributes[i].Name);

                        TreeNode LearningLessionValue = new TreeNode(LearningTrackXMLNode.Attributes[i].Value);

                        LearningLession.ChildNodes.Add(LearningLessionValue);
                        LearningTrackNode.ChildNodes.Add(LearningLession);
                    }
                }
                if (LearningTrackXMLNode.ChildNodes[0] != null)
                {
                    if (LearningTrackXMLNode.ChildNodes[0].NodeType == XmlNodeType.Text)
                    {
                        TreeNode LearningLession = new TreeNode("Text");
                        TreeNode LearningLessionValue = new TreeNode(LearningTrackXMLNode.InnerText, LearningTrackXMLNode.Value);

                        LearningLession.ChildNodes.Add(LearningLessionValue);
                        LearningTrackNode.ChildNodes.Add(LearningLession);
                    }
                }
            }
        }
   
    private void BindLearningTrackLessonsAndTopics(string learningTrackName)
    {
        LearningTrackByLearningTrackTitleDataSet LearningTrackByLearningTitle = new LearningTrackByLearningTrackTitleDataSet();
        LearningTrackByLearningTrackTitleDataAdapter LearningTrackByLearningTitleDA = new LearningTrackByLearningTrackTitleDataAdapter();
       
        LearningTrackByLearningTitleDA.Fill(LearningTrackByLearningTitle, learningTrackName);

        XmlDataDocument LearningTrackAndLessionsXmlDocuments = new XmlDataDocument(LearningTrackByLearningTitle);
       
        DataSet LearningTrackAndLessionDataSource = new DataSet();

        LearningTrackAndLessionDataSource.ReadXml(new XmlNodeReader(LearningTrackAndLessionsXmlDocuments));


        LearningTrackAndLessionsXmlDataSource.Data = LearningTrackAndLessionsXmlDocuments.InnerXml;
        LearningTrackAndLessoinTreeView.DataSource = LearningTrackAndLessionsXmlDataSource;
        LearningTrackAndLessoinTreeView.DataBind();
    }
}

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Nilesh
Top achievements
Rank 1
Share this question
or