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

[Solved] Show treeview from select ID

4 Answers 140 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Juan Carlos Carrasco
Top achievements
Rank 1
Juan Carlos Carrasco asked on 24 Nov 2009, 11:29 PM
Hi i want show my treeview from select ID like this:

CustomerID     parentafi
1                      NULL
2                      1
3                      2
4                      2
5                      2
6                      5

i want only show from CustomerID = 5
so like this:

CustomerID        parentafi
5                        2
6                        5

how i can do????? Thx!

Juanca

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 26 Nov 2009, 01:23 PM
Hi Juan Carlos Carrasco,

Your sql query can look like this:

SELECT * FROM YOUR_TABLE WHERE CustomerID = 5 OR parentafi = 5


Best wishes,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Juan Carlos Carrasco
Top achievements
Rank 1
answered on 27 Nov 2009, 02:26 AM
Dont work,  cuz only show in query SQL

CustomerID    parentafi 
2                    1
3                    2
4                    2
5                    2
but dont show 
6                    5

and the same error in my web 
"You can enable this restriction since all values have corresponding primary values"
treeView.DataBind();



 
0
Accepted
Veselin Vasilev
Telerik team
answered on 27 Nov 2009, 02:33 PM
Hi Juan Carlos Carrasco,

I suggest that you send us a sample running project which exhibits the problem. We will test it locally and find a solution.

Greetings,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Juan Carlos Carrasco
Top achievements
Rank 1
answered on 29 Nov 2009, 05:54 PM
Ok I got it!!
           SqlDataAdapter adapter = new SqlDataAdapter("Select_Afi", Read_cnx());  
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;  
            adapter.SelectCommand.Parameters.AddWithValue("@ParentAfi", 2);  
 
            DataTable table = new DataTable();  
 
            adapter.Fill(table);  
 
            DataTable TableTemp = new DataTable();  
            TableTemp.Columns.Add("CustomerID"typeof(string));  
            TableTemp.Columns.Add("Icon"typeof(string));  
            TableTemp.Columns.Add("FirstName"typeof(string));  
            TableTemp.Columns.Add("Parentafi"typeof(string));  
 
 
            string Cust, Icon, Name, PAfi;  
              
            for (int i = 0; i < table.Rows.Count; i++)  
            {  
                DataRow row = TableTemp.NewRow();  
                Cust = table.Rows[i][0].ToString();  
                Icon = table.Rows[i][1].ToString();  
                Name = table.Rows[i][2].ToString();  
                PAfi = table.Rows[i][3].ToString();  
                if (Convert.ToInt32(table.Rows[i][0].ToString()) == 2)  
                {  
                    string n = null;  
                    row["Parentafi"] = n; ;  
                }  
                else 
                {  
                    row["Parentafi"] = PAfi;  
                }  
                row["CustomerID"] = Cust;  
                row["Icon"] = Icon;  
                row["FirstName"] = Name;  
 
                TableTemp.Rows.Add(row);  
            }  
 
            treeView.DataTextField = "FirstName";  
            treeView.DataFieldID = "CustomerID";  
            treeView.DataFieldParentID = "Parentafi";  
 
            treeView.DataSource = TableTemp;  
            treeView.DataBind(); 

Its working! Thx everyone!
Tags
TreeView
Asked by
Juan Carlos Carrasco
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Juan Carlos Carrasco
Top achievements
Rank 1
Share this question
or