I have defined a custom CommandItemTemplate which contains a LinkButton
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.
<
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
0
Accepted

Shinu
Top achievements
Rank 2
answered on 05 Aug 2010, 10:42 AM
Hello Ryan,
Use the following code snippet to access the LinkButton placed in CommandItemTemplate.
C#:
-Shinu.
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:
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?
<
CommandItemTemplate
>
<
XXX:FilterBar
runat
=
"server"
/>
<
XXX:HeaderBar
runat
=
"server"
/>
</
CommandItemTemplate
>
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
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
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:
Well, all-in-all such approach seems very unreliable...
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
Hi Alexander,
In the ItemCreated event, you should be able to access the GridCommandItem and its controls as below:
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
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
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
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.