Hello,
Is there a way to bind a RadToolbar programmatically in the code behind to a RadGrid?.
The reason I need this is because I have created a three tier Hierarchy grid in the page init, which I want to eventually edit with the radtoolbar.
I know that I can do RadGrid1.MasterTableView.CommandItemDisplay = ?? but I am having problems finding out how to bind the radtoolbar itself.
Perhaps someone can guide me to a document or the steps I need to do?
Thanks.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 12 Aug 2009, 06:26 AM
Hi Daniel,
I am not sure whether you are having difficulty in defining the CommandItemTemplate programmatically or accessing a control from the CommandItemTemplate in code behind. Any ways here I am pasting the code snippet for the both the requirements.
CS:
Best Regards
Princy
I am not sure whether you are having difficulty in defining the CommandItemTemplate programmatically or accessing a control from the CommandItemTemplate in code behind. Any ways here I am pasting the code snippet for the both the requirements.
CS:
| protected override void OnInit(EventArgs e) |
| { |
| //InitializeComponent; |
| DefineGridStructure(); |
| base.OnInit(e); |
| } |
| private void DefineGridStructure() |
| { |
| RadGrid RadGrid1 = new RadGrid(); |
| //create the hierarchical Grid here |
| //......... |
| ....... |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; |
| RadGrid1.MasterTableView.CommandItemTemplate = new MyCommandItemTemplate(); |
| RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound); |
| //Add the RadGrid instance to the controls |
| this.PlaceHolder1.Controls.Add(RadGrid1); |
| } |
| private class MyCommandItemTemplate : ITemplate |
| { |
| protected RadToolBar toolbar; |
| public MyCommandItemTemplate() |
| { |
| } |
| public void InstantiateIn(System.Web.UI.Control container) |
| { |
| toolbar = new RadToolBar(); |
| toolbar.ID = "toolbar1"; |
| container.Controls.Add(toolbar); |
| } |
| } |
| // accessing the RadToolBar from the CommandItemTemplate in code behind |
| void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridCommandItem) |
| { |
| GridCommandItem cmdItem = (GridCommandItem)e.Item; |
| // access the tool bar here |
| RadToolBar toolbar = (RadToolBar)cmdItem.FindControl("toolbar1"); |
| } |
| } |
Best Regards
Princy
0
Daniel
Top achievements
Rank 1
answered on 13 Aug 2009, 04:10 PM
Thanks, this helped.
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2009, 07:09 AM
Hi Daniel,
You may also go through the following help article which explains how to define CommandItemTemplate dynamically. Go through the section entitled 'Define CommandItemTemplate programmatically' .
Regards
Princy
You may also go through the following help article which explains how to define CommandItemTemplate dynamically. Go through the section entitled 'Define CommandItemTemplate programmatically' .
Regards
Princy