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

Get reference from CommandItemTelplate of RadGrid in Page_Load event

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shannnon
Top achievements
Rank 1
Shannnon asked on 15 Feb 2011, 08:17 PM
I have a CommandItemTemplate contain RadToolBar which also contain RadComboBox, what i need to do here is to dynamically set value for the RadComboBox when page is loaded and in button click event. This is the code I have in Page_Load/Button_Click event:  
GridItem commandItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
                RadToolBar radtoolbar = (RadToolBar)commandItem.FindControl("RadToolBar1");
                RadToolBarItem comboitem = radtoolbar.FindItemByText("RadToolBarButton1");
                RadComboBox rcb = (RadComboBox)comboitem.FindControl("RadComboBox1");
 I kept getting "Index was outside the bounds of the array" but I have only one Item (RadToolBar) in CommandItemTemplate. I saw samples that do it in ItemCreate event, but I need my control to interact with button click, how can I do it?

Thanks  in advance!

Shannon

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Feb 2011, 06:00 AM
Hello Shannon,

Check whether you have set 'CommandItemDisplay' property of MasterTableView. And if you want to set value to RadComboBox, try it in PreRender event of RadGrid than PageLoad event.

ASPX:
<MasterTableView  CommandItemDisplay="Top">

C#:
protected void Button1_Click(object sender, EventArgs e)
  {
     GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
   }

protected void RadGrid1_PreRender(object sender, EventArgs e)
  {
      GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
  }

Thanks,
Princy.
0
Shannnon
Top achievements
Rank 1
answered on 16 Feb 2011, 10:25 PM
Thank you Princy!
Tags
Grid
Asked by
Shannnon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shannnon
Top achievements
Rank 1
Share this question
or