Export 1 NestedViewTemplate to Html

2 posts, 0 answers
  1. Anders
    Anders avatar
    30 posts
    Member since:
    Jul 2013

    Posted 08 Oct 2013 Link to this post

    I have RadGrid with a quit extended NestedView where I show the details if the Item in a Html table. The Html is styled and there is photos in the table.

    Now I would like to export only this NestedViewTemplate from this one Grid Item when the user click on a button inside the NestedViewTemplate.

    Is this possible?

    I have tried modify this sample:

    http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-export-to-excel-biff-format-hierarchy-and-selected-items.aspx#2816333 

    By adding a NestedViewTemplate an expand those in the Prerender event. But first of I can't it to print the NestedViewTemplate and the export contains the headers.

    Could some one point me in the right direction?  Thanks :-)

    bool isExport = false;
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["SelectedItems"] = RadGrid1.SelectedItems;
        isExport = true;
     
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.ExportSettings.UseItemStyles = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
     
        RadGrid1.MasterTableView.ExportToExcel();
    }
     
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (isExport)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                item.Expanded = true;
            }
        }
    }

    Anders Pedersen

  2. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 11 Oct 2013 Link to this post

    Hi Anders,

    In the help topic which you have provided is demonstrates an approach which is suitable when you are using an ExcelML export format. Since you are trying to export a NestedViewTemplate I guess you  are using an HTML on. In this case you have to loop though all items and set their Visible property to false and leave visible only the one which is expanded. Please check out the following code snippet.
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            if (!item.Expanded)
            {
                item.Visible = false;
            }
        }
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.ExportSettings.UseItemStyles = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
      
        RadGrid1.MasterTableView.ExportToExcel();
    }

    Regards,
    Kostadin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top