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

export to csv, cant find button

2 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 28 Jun 2010, 10:00 AM
I am creating several buttons in the the commandItemTemplate, I am using these to export tp csv plus many other things (I could use the commandItemSettings but dont want to). The problem I am having is that I cannot find the buttons in the code behind.  My code is as follows.

 
 
<telerik:RadAjaxLoadingPanel runat="server" ID="progressLoader" MinDisplayTime="1500" InitialDelayTime="1000" Skin="Default"></telerik:RadAjaxLoadingPanel> 
<telerik:RadAjaxPanel runat="server" ID="rap_panel1" LoadingPanelID="progressLoader">  
        <telerik:RadGrid ID="RadGrid1"    
                         runat="server"   
                         GridLines="Vertical" 
                         ShowGroupPanel="True"   
                         PageSize="18"   
                         AllowSorting="true"   
                         AllowPaging="true"   
                         AutoGenerateColumns="false"   
                         EnableHeaderContextMenu="true" 
                         Skin="Default">              
            <ExportSettings> 
                <Pdf FontType="Subset" PaperSize="A4" /> 
                <Excel Format="Html" /> 
                <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> 
            </ExportSettings> 
            <MasterTableView DataKeyNames="ROWCLICK" GroupLoadMode="Client" CommandItemDisplay="Top">  
                <PagerStyle  Mode="NextPrevNumericAndAdvanced" /> 
 
               <CommandItemTemplate> 
 
                      <asp:LinkButton ID="btn_save" runat="server" CommandName="saveGrid" ><asp:Image runat="server" ID="img_save" ImageUrl="~/_resources/images/icons/tick.png"/></asp:LinkButton> 
                        <asp:LinkButton ID="btn_excel" runat="server" CommandName="excel" ><asp:Image runat="server" ID="Image1" ImageUrl="~/_resources/images/icons/xls_grey.gif"/></asp:LinkButton> 
                        <asp:LinkButton ID="btn_pdf" runat="server" CommandName="pdf" ><asp:Image runat="server" ID="Image2" ImageUrl="~/_resources/images/icons/pdf.gif"/></asp:LinkButton> 
                          
                      
                </CommandItemTemplate> 
            </MasterTableView> 
            <ClientSettings ReorderColumnsOnClient="True"   
                            AllowDragToGroup="True"   
                            AllowColumnsReorder="True"   
                            EnablePostBackOnRowClick="true"   
                            AllowGroupExpandCollapse="true">  
                <Resizing AllowRowResize="True"   
                          AllowColumnResize="True"   
                          EnableRealTimeResize="True" 
                          ResizeGridOnColumnResize="False">  
                </Resizing> 
            </ClientSettings> 
        </telerik:RadGrid> 
</telerik:RadAjaxPanel> 


    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
 
        Dim item As GridCommandItem = TryCast(e.Item, GridCommandItem)  
        If item IsNot Nothing Then 
            Dim btn As Button = TryCast(item.FindControl("btn_excel"), Button)  
 
        End If 
 
    End Sub 

Any help would be much appreciated.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Jun 2010, 11:04 AM
Hello Russell,

I am happy to help you. The following code snippet will be useful for you in achieving this.

VB.NET:
 
 Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridCommandItem Then 
        Dim item As GridCommandItem = TryCast(e.Item, GridCommandItem) 
        If item IsNot Nothing Then 
            Dim btn As LinkButton = TryCast(item.FindControl("btn_excel"), LinkButton) 
        End If 
    End If 
 End Sub 
 

Thanks,
Princy.


0
mabs
Top achievements
Rank 1
answered on 28 Jun 2010, 11:25 AM
Thank you works a treat, didn't spot the mistake untill you posted your solution!
Tags
Grid
Asked by
mabs
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mabs
Top achievements
Rank 1
Share this question
or