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

Export individual DetailsTable by clicking button in MasterTable

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lalit
Top achievements
Rank 1
Lalit asked on 20 Mar 2014, 05:13 PM
I am creating a RadGrid from code behind. The MasterTable carries a template column with an Export button to export the underlying DetailsTable. The DetailsTable is not expanded by default. It only expands when (>) is clicked on the MasterTable.

The problem is Export doesnt work as it should. It exports the data from the MasterTable and not the DetailsTable.

Here is some portion of my code:
.....
Creating RadGrid1...
Creating a Master Table.....
Adding template column...
TemplateColumn = new GridTemplateColumn();
string ExportColumnName = "Export";
TemplateColumn.ItemTemplate = new MyExportTemplate(ExportColumnName);
TemplateColumn.HeaderText = ExportColumnName;
RadGrid1.MasterTableView.Columns.Add(TemplateColumn);

Creating a Details table....
...
Add everything to a RadAjaxPanel on the page.

.....
 public class MyExportTemplate : ITemplate
    {
        private string colname;
        public MyExportTemplate(string cName)
        {
            colname = cName;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            RadButton REB = new RadButton();
            REB.Text = "Print Report";
            REB.Click += REB_Click;
            container.Controls.Add(REB);
        }

        void REB_Click(object sender, EventArgs e)
        {
            GridTableView table = ((sender as RadButton).NamingContainer as GridItem).OwnerTableView;
            table.ExportToPdf();
        }

    }

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 25 Mar 2014, 11:43 AM
Hi Lalit,

As far as I can see you are getting the master table view instead the detail table. Please try using the following approach to access the detail table view on Button click event handler.
GridTableView table = (((sender as RadButton).NamingContainer as GridDataItem).ChildItem as GridNestedViewItem).NestedTableViews[0] as GridTableView;

Regards,
Kostadin
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Grid
Asked by
Lalit
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or