Problem Binding TreeView

2 posts, 0 answers
  1. gs1711
    gs1711 avatar
    12 posts
    Member since:
    Nov 2010

    Posted 15 Dec 2010 Link to this post

    I have followed this simple example and implemented similarly:-

    The problem:- GetDataSet() method returns a DataSet with the complete Ques table with all the rows and columns(QuesID,QuesParentID,QuesAns,Active,QuesTypeID and so on)

    Now the probelm is that the RadTreeview is not binding well. Like The root node displays Questions but the the child nodes are not displaying the correspoding answer. Also, some root nodes do not have a child node at all. Those root nodes that DO have a child node are displaying Questions as their text and not Answers. I surmise it's something wrong with the BindTree() method only. What could it be? I mean RADTreeView is implemented in a very simple manner in that link above. I only followed accordingly. What is wrong??

    aspx page;-

    <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <telerik:RadTreeView runat="server" ID="tree1" OnNodeDataBound="tree1_NodeDataBound"></telerik:RadTreeView>


    Code Behind :-

     public partial class TestTree :
    System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)

    private DataSet GetDataSet()
                bllQues objbllQues
    = new bllQues();
    var ds = new DataSet();
    return objbllQues.GetQues();


    protected void BindTree(RadTreeView treeView)
    DataSet ds = new DataSet();
    = GetDataSet();
    .DataTextField = "Ques";
    .DataValueField = "QuesAns";
    .DataFieldID = "QuesID";
    .DataFieldParentID = "QuesParentID";
    .DataSource = ds;

    protected void tree1_NodeDataBound(object sender,
    RadTreeNodeEventArgs e)
    .Node.ToolTip = (e.Node.DataItem as
    } }

  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 17 Dec 2010 Link to this post

    Hello gs1711,

    I would have to assume, based on your table, that you are storing the question/answer for each row, whether its a root node or a child node. SO pretty much you answer records have the question column set (Ques). Am I right in thinking that? If so, you set the DataTextField to Ques, which will always show the question and not the answer (QuesAns).

    If you only have once root questions and no sub questions, you can use the DataBindings collection to control what the DataTextField is for the first level of nodes and then change the default DataTextField to the answer.

    I hope that helps.
Back to Top