How to call RadGrid.MasterTableView.ExportToExcel() from RadMenu?

3 posts, 1 answers
  1. Bernhard
    Bernhard avatar
    8 posts
    Member since:
    Apr 2009

    Posted 10 Mar 2010 Link to this post

    Hi,

    in the Master I have a Rad menu, which gets the items from a siteMap-File
    <telerik:RadMenu ID="radMenu" runat="server"      
     DataSourceID="siteMapDataSource" onitemclick="radMenu_ItemClick" /> 

    In the method radMenu_ItemClick I tried to get a reference to the RadGrid in the current Page. (I assume here that the correct page is currently loaded)
    protected void radMenu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)  
       {  
          Tasklist tasklistGUI = radMenu.Page as Tasklist;  
          RadGrid tasklistRadGrid = tasklistGUI.FindControl("RadGrid1"as RadGrid;  
          tasklistRadGrid.MasterTableView.ExportToExcel();  
       } 

    The idea is then to call ExportToExcel as a method of the referenced object. But the object is null!
    What's wrong? What must I do to get a working reference to the RadGrid?

    Thank you very much in advance.

    Regards
    Bernhard
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Mar 2010 Link to this post

    Hi,

    You can access  the RadGrid from the ContentPlaceholder of the Master page which will hold the contents  as shown below:

    C#
     protected void radMenu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) 
        { 
            RadGrid tasklistRadGrid = ContentPlaceHolder1.FindControl("RadGrid1"as RadGrid; 
            tasklistRadGrid.MasterTableView.ExportToExcel(); 
        }  


    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bernhard
    Bernhard avatar
    8 posts
    Member since:
    Apr 2009

    Posted 11 Mar 2010 Link to this post

    Hi Princy,

    this exactly has solved my problem.
    Many Thanks!

    Regards
    Bernhard
Back to Top