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

Problem With the Export to excel.

1 Answer 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sankar
Top achievements
Rank 1
Sankar asked on 10 Sep 2015, 09:50 AM

Hi Telerik,

               I have a Problem With the Export to excel. In my case, I created the multiple radgrids dynamically from Code - behind and add it into the Placeholder. I have enabled the default Export to excel button for all grids. I haven't use any ajax panels, but I use Update panel. When i click the default Export to excel button, all grids are invisible and excel did not generated.

 Code:

   Dim dset As DataSet
        Dim col_count As Integer

        For i As Integer = 0 To c - 1

            Dim radgrid1 As New Telerik.Web.UI.RadGrid
            radgrid1.ID = "RadGrid" & i
            radgrid1.ExportSettings.Excel.Format = GridExcelExportFormat.Html
            radgrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top
            radgrid1.MasterTableView.PageSize = "10"
            radgrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = True
            radgrid1.MasterTableView.DataKeyNames = New String() {"employee_id"}
            radgrid1.ExportSettings.ExportOnlyData = True

            radgrid1.ExportSettings.FileName = Pub_dset.Tables("tblCount").Rows(i).Item("sub_heading")
            radgrid1.MasterTableView.Caption = "Sub Heading - " & Pub_dset.Tables("tblCount").Rows(i).Item("sub_heading")
            radgrid1.AutoGenerateColumns = False
            radgrid1.ClientSettings.ClientEvents.OnCommand = "onRequestStart('this')"
            dset = DAL.details(9, 4, "", "", "", 0, 0, 0, CDate(Now), CDate(Now), CDate(Now), "", "", "", 0, "", "", 0, 0, i, "", 0, "", 0, 0, "", 0, CDate(Now), "tblBind")
            col_count = dset.Tables("tblBind").Columns.Count
            col_count = dset.Tables("tblBind").Columns.Count

            For j As Integer = 0 To dset.Tables("tblBind").Columns.Count - 1
                Dim Bcol As New GridBoundColumn
                Bcol.DataField = dset.Tables("tblBind").Columns(j).ColumnName
                Bcol.UniqueName = dset.Tables("tblBind").Columns(j).ColumnName
                Bcol.HeaderText = dset.Tables("tblBind").Columns(j).ColumnName
                Bcol.ShowFilterIcon = True
                Bcol.AllowFiltering = True
                Bcol.AllowSorting = True
                Bcol.ItemStyle.Wrap = False
                radgrid1.MasterTableView.Columns.Add(Bcol)
                If Bcol.UniqueName = "employee_id" Or Bcol.UniqueName = "emp_no" Then
                    radgrid1.MasterTableView.GetColumn(Bcol.UniqueName).Display = False
                End If
                If Bcol.DataField = "emp_name" Then
                    Bcol.HeaderText = "Employee Name"
                End If
            Next
            radgrid1.DataSource = dset.Tables("tblBind")

            radgrid1.Rebind()
            PlaceHolder1.Controls.Add(radgrid1)
            PlaceHolder1.Controls.Add(New LiteralControl("<br><br>"))
        Next

 

Please help me resolve this...

its very urgent...

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 11 Sep 2015, 01:23 PM
Hi Sankar,

First of all, please note that the NeedDataSource event is the mandatory way when you need to bind the grid to a programmatic data source in the code-behind. It is important that you are not using DataBind() to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding

If you need to refresh the grid content on an external action, let's say an outside Button click, you can simply use the RadGrid1.Rebind() method to do that. The DataSource property should only be set inside the NeedDataSource event handler.


Exporting from an ajaxified grid requires additional handling, therefore, I suggest that you replace the UpdatePanel with a RadAjaxPanel and implement the solution provided in the following article:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/ajaxified-radgrid/what-you-should-have-in-mind/export-from-ajaxified-grid

Hope this helps.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Sankar
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or