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

TreeView and Grid Columns

1 Answer 116 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 23 Nov 2011, 03:16 PM
Telerik,

Is there any way to dynamically change the columns of a RadGrid when selecting a node from a RadTreeView?

Basically what I have is a number of nodes in a tree view.  When selecting a specific tree view node I want to change the columns in a RadGrid and rebind.

Regards,

Jason

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Nov 2011, 08:03 AM
Hello,

I suppose you need to add columns on NodeClick. Try the following code snippet.
CS:
protected void Page_Load(object sender, EventArgs e)
 {
    // creating columns of RadGrid on PageLoad.
    if (!IsPostBack)
     {
        GridBoundColumn boundColumn;
        boundColumn = new GridBoundColumn();
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "EmployeeID";
        boundColumn.HeaderText = "EmployeeID";
        boundColumn = new GridBoundColumn();
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "FirstName";
        boundColumn.HeaderText = "FirstName";
      }
  }
 protected void treeview_NodeClick(object sender, RadTreeNodeEventArgs e)
   {
     // Column creating on NodeClick.
       GridBoundColumn boundColumn;
       boundColumn = new GridBoundColumn();
       grid.MasterTableView.Columns.Add(boundColumn);
       boundColumn.DataField = "LastName";
       boundColumn.HeaderText = "LastName";
       grid.Rebind();
   }

Thanks,
Princy.
Tags
TreeView
Asked by
Jason
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or