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

reference control in NestedViewTemplate problem

5 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
duheng
Top achievements
Rank 1
duheng asked on 26 May 2010, 08:47 PM
Hi,

I put a Panel in the nestedViewTemplate of a RadGrid. On the panel, I have a toolBar, then a inner grid.
What I want is:
When I click the button (export) on the toolBar, I will export the content of the inner grid.
What I did is:
I attached a OnOnClick="toolSearchResultsInner_OnClick" to the toolBar. In the code behind, I will set the export formatting for the innerGrid.
The problem is:
1) I can't get the reference control (inner grid) in the toolSearchResultsInner_OnClick event.
2) I searched a lot and found that people suggested using outGrid.itemCreated to access the controls inside the nestedViewTemplate. However, in my case, I want to export the inner grid only when I click the export button on the toolBar.

Can anybody help me?

Here is the code:
 <Telerik:RadGrid ID="dgResults" runat="server" AllowPaging="True" AllowSorting="True">  
<MasterTableView > 
 <NestedViewSettings > 
     <ParentTableRelation> 
       <telerik:GridRelationFields DetailKeyField="GeneralID" MasterKeyField="GeneralID" /> 
                        </ParentTableRelation>                                                
                   </NestedViewSettings> 
                    
                   <NestedViewTemplate> 
                   <asp:Panel runat="server" ID="InnerContainer" CssClass ="viewWrap" Visible="true">         
                <radtlb:radtoolbar runat="server" id="toolSearchResults1"  OnOnClick="toolSearchResultsInner_OnClick" AutoPostBack="true">  
         <items>                    
                                                <radtlb:radtoolbarbutton ID="toolExport" DisplayType="TextImage"  CommandName="Export to Excel" ButtonImage="IFExcel.jpg" Hidden="False" runat="server" style=" font-weight:normal;font-family:Tahoma" ButtonText="Export" /> 
                                <radTlb:RadToolbarSeparator ID="RadToolbarSeparator31" runat="server" /> 
                                <radtlb:radtoolbarbutton ID="toolPrint" DisplayType="TextImage"  CommandName="Print" ButtonImage="print.gif" Hidden="False" runat="server" style=" font-weight:normal;font-family:Tahoma" ButtonText="Print" /> 
                                                                </item></radtlb:radtoolbar>   
      <telerik:radGrid ID ="innerGrid" runat ="server"  AllowPaging="True" AllowSorting="True" OnExcelExportCellFormatting="Inner_ExcelExportCellFormatting" 
</MasterTableView > 
      <MasterTableView TableLayout ="auto" >                 
 
 
              </MasterTableView> 
                              
            </telerik:radGrid> 
 
          </asp:Panel> 
        </NestedViewTemplate> 
     </MasterTableView> 
</Telerik:RadGrid> 
 

Best regards,
Heng

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 May 2010, 10:50 AM
Hello Duheng,

In order to achieve this, access the GridNestedViewItem by using the NamingContainer property of RadToolBar control. Then use FindControl() method to get reference to the grid inside NestedViewTemplate.

C#:
  
 protected void toolSearchResultsInner_OnClick(object sender, RadToolBarEventArgs e) 
    { 
        RadToolBar button = (RadToolBar)sender; 
        GridNestedViewItem nesteditem = (GridNestedViewItem)button.NamingContainer; 
        RadGrid grid = (RadGrid)nesteditem.FindControl("innerGrid"); 
        //code for exporting the content of innerGrid 
    } 

Regards,
Shinu.


0
duheng
Top achievements
Rank 1
answered on 28 May 2010, 05:04 PM
Hi Shinu,

Thank you very much. I tried your way and it worked.

Can I ask you another question? It's about getting reference of the control in javascript.

Usually we can use $find(gridID) to get the reference. However, I found that in some javascript functions, it works, not not for the others.

For example, I want to print the outer grid in my first post. I have a toolBarButton "print". When I click it, it will call click_handler function in javascript.

 <%= toolSearchResults.ClientID %>.attachEvent("OnClientClick","click_handler");  
 function click_handler(sender,e)  
    {  
 if(sender.CommandName == "Print")  
        {  
      var grid=$find("<%=dgResults.ClientID %>");  
            var gridgridView=grid.get_masterTableView();  
            var gridgridHeader=grid.get_masterTableViewHeader();  
            var allele=gridView.get_dataItems();  
            var WinPrint = window.open('','','left=100,top=100,width=1000,height=1000,toolbar=0,scrollbars=1,status=0,resizable=1');     
              
            WinPrint.document.write(grid._element.outerHTML);               
            WinPrint.document.close();     
            WinPrint.focus();     
            WinPrint.print();     
            WinPrint.close();  
}  
In this way, I can get the reference of the outergrid. However, it only printed the current page. I want it to print out all of pages at once.
So I followed the example in http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-print.aspx
but I can't get the reference of grid in the  PrintRadGrid(radGridId) function. 

var radGrid = $find(radGridId); it gave me null.

Here is my code behind:

if (e.Button.CommandName == "Print")  
            {  
                dgResults.AllowPaging = false;  
                dgResults.Rebind();  
                RadAjaxManager1 .ResponseScripts.Add("PrintRadGrid('" + dgResults.ClientID + "')");  
              
            } 

here is the printGrid function in javascript:

function PrintRadGrid(radGridId)  
            {  
             
          var radGrid = $find(radGridId);  
               
                var previewWnd = window.open('about:blank', '', '', false);  
                var sh = '<%= ClientScript.GetWebResourceUrl(dgResults.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",dgResults.Skin)) %>';  
                var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";  
                var htmlcontent = styleStr + "<body>" + radGrid.outerHTML + "</body></html>";  
                previewWnd.document.open();  
                previewWnd.document.write(htmlcontent);  
                previewWnd.document.close();  
                previewWnd.print();  
                previewWnd.close();  
            } 

Can you help me out? Thanks.

0
Pavlina
Telerik team
answered on 01 Jun 2010, 12:16 PM
Hello,

Please find attached a simple working application which handles the desired functionality. Give it a try and let me know what is the difference in your case.

All the best,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
duheng
Top achievements
Rank 1
answered on 01 Jun 2010, 02:29 PM
Hi,

I tried your sample but it didn't work. I still got null for radGrid. Actually yours is the same with this one which I tried earlier:  http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-print.aspx

The only difference between my code with this sample is that: I used 

<

 

radA:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX ="true">

 

and 

RadAjaxManager1.ResponseScripts.Add(

"PrintRadGrid('" + dgResults.ClientID + "')");

 


Can you give me more help? Thanks.

Heng
0
Pavlina
Telerik team
answered on 02 Jun 2010, 03:36 PM
Hello Heng,

It would be great if you could send us a sample project illustrating the described behavior. Thus I could debug it locally and investigate the issue in depth, so I could provide a proper solution.

Thank you for your cooperation in advance.

Kind regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
duheng
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
duheng
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or