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

Problem with sort nodes

1 Answer 42 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Salman
Top achievements
Rank 1
Salman asked on 06 Jan 2012, 06:36 PM
Hi
I have a treeview which bind to a Datatable  which is code in the follow
private void fillContractItem()
  
{
  
trvContractItem.DataFieldID = "iNumber";
  
trvContractItem.DataFieldParentID = "iParentNumber";
trvContractItem.DataTextField = "strName";
trvContractItem.DataValueField = "iNumber";
 trvContractItem.DataSource = objContractItem.SelectAll();
trvContractItem.DataBind();
  
}


I want node sort by a filed(name filed is orderfiled in in datatable
how i can move  nodes to up or down in a level  then save order nodes in orderfiled and load nodes by orderfiled and show to users
thanks 

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 09 Jan 2012, 02:23 PM
Hi Salman,

 
You can sort the tree in the code behind as shown in the code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindToDataSet(RadTreeView1);
 
        }
    }
    private static void BindToDataSet(RadTreeView treeView)
    {
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Employees",
                ConfigurationManager.ConnectionStrings["TelerikVSXConnectionString"].ConnectionString);
 
        DataSet links = new DataSet();
 
        adapter.Fill(links, "Employees");
        DataView view = links.Tables["Employees"].DefaultView;
        // To sort in ascending order:
 
       // view.Sort = "LastName" + " ASC";
        // To sort in descending order:
        view.Sort = "LastName" + " DESC";
 
        treeView.DataTextField = "LastName";
        treeView.DataFieldID = "EmployeeID";
        treeView.DataFieldParentID = "ReportsTo";
 
        treeView.DataSource = view;
        treeView.DataBind();
    }

Please find attached a sample project.

Hope this will be helpful.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
Salman
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or