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

Accessing a button inside a command Template

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Giblin
Top achievements
Rank 1
John Giblin asked on 30 Nov 2012, 03:20 PM
I cant seem to be able to access btnCreateVersion inside of the RadGrid--> MasterTableView -->DetailTables -->GridTableView

I am adding security and need to be able to access the button and make it visible if the user has access to it.

What is the best was of doing this

<CommandItemTemplate>
                                         <asp:ImageButton ID="btnCreateVersion" runat="server" CommandName="CreateVersion" ImageUrl="~/Image/epi_add.png"
                                             Height="14px" Visible="true"></asp:ImageButton>
                                         <asp:LinkButton ID="lblCrtEpi" runat="server" Text="Create Versions" CommandName="CreateVersion" Visible="true"></asp:LinkButton>  
                                     </CommandItemTemplate>

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Dec 2012, 04:19 AM
Hello,

protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       HideExpandColumnRecursive(RadGrid1.MasterTableView);
   }
 
   public static void HideExpandColumnRecursive(GridTableView tableView)
   {
       GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
       foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
       {
           foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
           {
               GridItem cmdItem = nestedView.GetItems(GridItemType.CommandItem)[0];
               LinkButton approveAllLink = cmdItem.FindControl("btnCreateVersion") as LinkButton;
               //Access link button here
               HideExpandColumnRecursive(nestedView);
           }
       }
   }


//OR

protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
       {  
           if (item.HasChildItems)
           {
               GridItem cmdItem = item.ChildItem.NestedTableViews[0].GetItems(GridItemType.CommandItem)[0];
               LinkButton approveAllLink = cmdItem.FindControl("btnCreateVersion") as LinkButton;
               //Access link button here
           }
       }
   }


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