2

I face the following problem : when i try to bind Telerik Treeview

These columns don't currently have unique values.


My code :

protected void BindRTV()
{
    rtv_acd.DataTextField = "name";
    rtv_acd.DataValueField = "main_id";
    rtv_acd.DataFieldID = "main_code";
    rtv_acd.DataFieldParentID = "father_code";
    rtv_acd.DataSource = dt;
    rtv_acd.DataBind();
}

Data snapshot :

enter image description here

How to fix this problem, i know that the main_code is repetitive but i want that .

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • I've not really used the telerik controls but with most controls the DataValueField is usually a unique identifier. – Ben Robinson Mar 11 '13 at 13:29

3 Answers3

5

There is a parent-child relationship between nodes, and the relation works with values specified in DataFieldID and DataFieldParentID members. So you have to specify a field with unique values for DataFieldID member.

Suppose you have two nodes with ID (main_code) of 1 (you already have), and there is another node with parent ID (father_code) of 1. So which of the two nodes are the parent of this node?

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
  • What if they're duplicate string values (and you're not using IDs)? Could it not treat any string value with the same value as the same parent? – PeterX Apr 12 '13 at 00:12
  • @PeterX Do you mean it should make a single node for two items with the same string value? – Mohammad Dehghan Apr 12 '13 at 07:16
1

As Mohammad said you should have at least one unique key column (without repetition). If don't this error will happens when you try to set primary key.

Also take into consideration that you don't have blank rows in that table, that indeed consider as unique column and I had this error.

The best way is to get distinct rows with certain number of column of consideration.

Check with telerik developer forum [1] http://www.telerik.com/forums/fetching-distinct-rows-from-datatable-using-linq [2] http://www.telerik.com/forums/display-distinct-values [3] http://www.telerik.com/forums/adding-5000-distinct-record-for-a-column-based-on-which-grouping-is-done-causing-ie-crash

In this Telerik also replied that you should use a unique column key.

Another tweak may be selecting datatable as distinct values [4]http://www.telerik.com/forums/radtreeview-selectednode-value

Contact them if you havent resolved this at developer forum

Chandy Kunhu
  • 66
  • 1
  • 8
1

this is about sql table and primary key for your table and you have duplicate data in your table feld