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

Setting the buttons when used as a RadGrid CommandItem

6 Answers 93 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 27 May 2009, 11:49 AM
I've a grid in a UserControl. The CommandItem template is defined like this ...
        <CommandItemTemplate> 
        <telerik:RadToolBar runat="server" ID="GridCommandItemToolbar" AutoPostBack="false" Skin="WebBlue" 
            OnClientButtonClicked="ToolBarButtonClicked" Style="width: 100%" Visible="true"
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
            <Items> 
                <telerik:RadToolBarButton runat="server" Enabled="false" ToolTip="Add Document" Value="AddDocument" ImageUrl="~/Images/Office/document_file/png/16/document_add_16x16.png"
                </telerik:RadToolBarButton> 
                <telerik:RadToolBarButton runat="server" Enabled="false" ToolTip="Edit Document" Value="EditDocument" ImageUrl="~/Images/Office/document_file/png/16/document_edit_16x16.png"
                </telerik:RadToolBarButton> 
                <telerik:RadToolBarButton runat="server" Enabled="false" ToolTip="Delete Document" Value="DeleteDocument" ImageUrl="~/Images/Office/document_file/png/16/document_delete_16x16.png"
                </telerik:RadToolBarButton> 
                <telerik:RadToolBarButton runat="server" IsSeparator="true"></telerik:RadToolBarButton> 
                <telerik:RadToolBarButton runat="server" Enabled="false" ToolTip="View Document History" Value="ViewHistory" CheckOnClick="true" Checked="false" AllowSelfUnCheck="true" ImageUrl="~/Images/Office/document_file/png/16/document_properties_16x16.png"
                </telerik:RadToolBarButton> 
 
            </Items> 
        </telerik:RadToolBar> 
        </CommandItemTemplate> 

I need to be able to enble/disable the buttons based on values and events on the calling page.

I thought to do it like this ...
var tb = $find("<%= GridCommandItemToolbar.ClientID %>"); 
But "GridCommandItemToolbar" isn't recognised, which I suppose is OK. But I can't seem to create a property on the UserControl that lets me get at the ToolBar server-side so I can access its ClientID in the <% %> code block on the page.

Can anyone offer a solution?

--
Stuart






6 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 27 May 2009, 12:57 PM
Never mind chaps, I've sorted it.

For the curious amongst you, the answer appears to be to:
  1. Create a global variable on your calling page,
  2. Wire up the OnClientLoad toolbar client-side event,
  3. In the event handler access the object in the previously declared gloabl variable.

Clever me! 8-)

--
Stuart
0
Stuart Hemming
Top achievements
Rank 2
answered on 27 May 2009, 02:59 PM
Well, I'd sorted it for accessing the ToolBar on the client, but now I need access to the ToolBar server-side.

Hints anyone?

--
Stuart
0
Stuart Hemming
Top achievements
Rank 2
answered on 27 May 2009, 03:06 PM
I could get at using...
RadToolBar tb = (RadToolBar)RadGrid1.MasterTableView.Controls[0].Controls[0].Controls[0].Controls[0].Controls[1]; 
but that can't be the right/best way, can it?

--
Stuart

0
Stuart Hemming
Top achievements
Rank 2
answered on 28 May 2009, 11:10 AM
Does anyone want to take a shot at this?

--
Stuart
0
Accepted
Iana Tsolova
Telerik team
answered on 28 May 2009, 11:42 AM
Hi Stuart,

You can try finding the ToolBar server side as shown below:

GridCommandItem commandItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem;  
RadToolBar toolBar = commandItem.FindControl("GridCommandItemToolbar"as RadToolBar; 

More information on how to access controls in RadGrid is available here.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stuart Hemming
Top achievements
Rank 2
answered on 28 May 2009, 12:42 PM
Iana,

Thanks for that. I would never have found that without reading all of the help file!

Thanks again!

--
Stuart
Tags
ToolBar
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or