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

How to "find" a radtoolbar in a radgrid

5 Answers 427 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stacy
Top achievements
Rank 1
Stacy asked on 13 Sep 2011, 07:25 PM
I have this layout:

<RadGrid>
   <MasterTableView>
      <CommandItemTemplate>
         <RadToolBar>

How can I "find" the radtoolbar to disable buttons?  I can do a "myControl.FindControl("myGrid")... but i cannot find the toolbar do enable/disable it.  I can also do a grid.MasterTableView.GetColumn("myButton").Visible = false but again, can't seem to "find" the toolbar or it's buttons.

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Sep 2011, 06:30 AM
Hello,

<CommandItemTemplate>
                   <telerik:RadToolBar ID="RadToolBar1" runat="server">
                       <Items>
                           <telerik:RadToolBarButton id="RadToolBarButton1" runat="server" Text="RadToolBarButton1"
                               Value="RadToolBarButton1">
                           </telerik:RadToolBarButton>
                       </Items>
                   </telerik:RadToolBar>
               </CommandItemTemplate>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                GridCommandItem item = (GridCommandItem)e.Item;
                RadToolBar RadToolBar1 = item.FindControl("RadToolBar1") as RadToolBar;
                RadToolBarButton RadToolBarButton1 = RadToolBar1.FindItemByValue("RadToolBarButton1") as RadToolBarButton;
                  
                // you can do your logic here
            }
        }


let me know if any concern.

Thanks,
Jayesh Goyani
0
Stacy
Top achievements
Rank 1
answered on 14 Sep 2011, 12:31 PM
Can this be used outside of the " RadGrid1_ItemDataBound" method?  This is not where I want to perform any logic. 
0
Princy
Top achievements
Rank 2
answered on 19 Sep 2011, 02:30 PM
Hello Stacy,

Try the following code snippet in Button Click.
C#:
protected void Button1_Click(object sender, EventArgs e)
  {
     GridCommandItem cmdItem = (GridCommandItem)grid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
     RadToolBar RadToolBar1 = cmdItem.FindControl("RadToolBar1") as RadToolBar;
     RadToolBarButton RadToolBarButton1 = RadToolBar1.FindItemByValue("RadToolBarButton1") as RadToolBarButton;
  }

Thanks,
Princy.
0
Stacy
Top achievements
Rank 1
answered on 19 Sep 2011, 03:14 PM
If I use this code below...I get an index out of range exception because there are 0
items returned from the "GetItems" call...it does find the grid and mastertableview, but GetItems returns 0 items

protected void Page_Load(object sender, EventArgs e)
{
            Initialize();
}
 
 private void Initialize()
{
GridCommandItem cmdItem = (GridCommandItem)grid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
}
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Sep 2011, 03:23 PM
Hello Stacy,

sorry but we are not able to get GridCommanditem in page load.
because after executing/completed the page_load event this GridCommandItem is created/generated so you have to do your functionality in Page_Prerender.

protected void Page_PreRender(object sender, EventArgs e)
    {
        GridCommandItem cmdItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
        RadToolBar RadToolBar1 = cmdItem.FindControl("RadToolBar1") as RadToolBar;
        RadToolBarButton RadToolBarButton1 = RadToolBar1.FindItemByValue("RadToolBarButton1") as RadToolBarButton;
        
    }

Let me know If any concern.

you can see ASP.NET Page Life Cycle Overview.
controls event fire after page_load.
so you can use above code any event but after the RadGrid_ItemCreated fired....like : button_click,page_prerender

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Stacy
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Stacy
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or