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

Problem Binding TreeView

1 Answer 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
gs1711
Top achievements
Rank 1
gs1711 asked on 15 Dec 2010, 08:22 AM

I have followed this simple example and implemented similarly:-

http://www.telerik.com/help/aspnet-ajax/tree_databindinghierarchical.html

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>

</asp:Content>

Code Behind :-

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

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

       
}

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

       
protected void tree1_NodeDataBound(object sender,
   
RadTreeNodeEventArgs e)
       
{
            e
.Node.ToolTip = (e.Node.DataItem as
   
DataRowView)["QuesAns"].ToString();
       
} }

1 Answer, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 17 Dec 2010, 02:35 PM
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.
Tags
TreeView
Asked by
gs1711
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Share this question
or