This is a migrated thread and some comments may be shown as answers.
Accessing CommandItemTemplate
10 Answers 243 Views
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 05 Aug 2010, 10:17 AM
I have defined a custom CommandItemTemplate which contains a LinkButton

<CommandItemTemplate>
  <div style="padding: 5px 5px;">
    <asp:LinkButton ID="linkBtnAddReport" runat="server" CommandName="InitInsert">
      <img style="border:0px;vertical-align:middle;" alt="" src="../../CSS/images/add.gif" /> Add New Report
    </asp:LinkButton>
  </div>
</CommandItemTemplate>

I need to change the Enabled property but I need to change it outside of the GridItemCommand event.

How can I find the LinkButton outside of the GridItemCommand event?

Thanks.

10 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 05 Aug 2010, 10:42 AM
Hello Ryan,


Use the following code snippet to access the LinkButton placed in CommandItemTemplate.

C#:
GridCommandItem cmdItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
LinkButton lnkButton = (LinkButton)cmdItem.FindControl("linkBtnAddReport");
lnkButton.Enabled = false;


-Shinu.
0
Ryan
Top achievements
Rank 1
answered on 05 Aug 2010, 10:51 AM
Thanks Shinu
0
Alexander
Top achievements
Rank 1
answered on 15 Dec 2010, 01:27 PM
Hi, i need something similar. I have CommandItemTemplate of such kind:
<CommandItemTemplate>
    <XXX:FilterBar runat="server" />
    <XXX:HeaderBar runat="server" />
</CommandItemTemplate>
Why I need this - because in FilterBar I might have a set of various controls for filtering grid data: textboxes, combos, etc.

HeaderBar should be filled programmatically.

I tried to access it from OnLoad event, but
MasterTableView.GetItems(GridItemType.CommandItem)
returns zero elements!

Maybe there's a better place to find HeaderBar control inside CommandItemTemplate and add controls to it?
0
Iana Tsolova
Telerik team
answered on 15 Dec 2010, 01:57 PM
Hello Alexander,

Try accessing it in the grid PreRender event, e.g. after the grid is once bound. On initial page load the grid is still not bound and its items are not created.

Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Alexander
Top achievements
Rank 1
answered on 15 Dec 2010, 02:33 PM
Thanks. I tried, but in PreRender it's zero either. So the problem is somewhere else...
0
Alexander
Top achievements
Rank 1
answered on 15 Dec 2010, 05:28 PM
In exprerimental way, discovered at last, how to make it work in ItemCreated event:
var headerBar_ = item.Controls[0].Controls.OfType<HeaderBar>().First();
Strange... Why I must access some sub controls, indexes, instead of accessing items directly via some property? What if some other time will be more than 1 controls in command item template somehow? :(
Well, all-in-all such approach seems very unreliable...
0
Iana Tsolova
Telerik team
answered on 20 Dec 2010, 12:52 PM
Hi Alexander,

In the ItemCreated event, you should be able to access the GridCommandItem and its controls as below:

protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridCommandItem)
    {
        GridCommandItem commandItem = e.Item as GridCommandItem;
        LinkButton lnk = commandItem.FindControl("lnk_ID") as LinkButton;
        .....
    }
}

You can refer to the below article for more information:
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

All the best,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Alexander
Top achievements
Rank 1
answered on 23 Dec 2010, 11:35 AM
Yeap, i've already understood the only possible way to distinct CommandItemTemplate was ItemCreated event... Ok :)
0
Mike
Top achievements
Rank 1
answered on 03 Sep 2017, 07:22 PM

Hi,

 

Has anyone found a better way to do this? I need to access a CommandItemTemplate control from outside the ItemCreated() event.

 

Thanks,

Mike

0
Eyup
Telerik team
answered on 06 Sep 2017, 06:04 AM
Hello Mike,

You can achieve this requirement using the approach demonstrated in the following section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/using-the--getitems-getcolumn-and-getcolumnsafe-methods#items

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Alexander
Top achievements
Rank 1
Iana Tsolova
Telerik team
Mike
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or