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

Noncomplaince of data between data on RadGrid and Exported Excel

3 Answers 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EIMCM
Top achievements
Rank 1
EIMCM asked on 03 Aug 2013, 02:19 PM
Hi, We currently use export to excel on data that is displayed on a grid..when any updates are made to database during the time when user is analyzing grid data, when he clicks export, the 'need data source' event fires again and the new updates are exported as well...this results in the exported data being different from the user analyzed data, that he saw on the grid....please let us know how to solve this, since it is very critical for obvious data compliance reasons...any help or pointers would be highly appreciated.

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 05 Aug 2013, 05:24 AM
Hi EIMCM,

Please try the below sample code snippet.It shows RadGrid operations along with export to excel.Also note that, the exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.If this doesn't help,please elaborate what updates you are making and provide your full code.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand" PageSize="15" >
    <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
    </ExportSettings>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToExcelButton="true" />
        <Columns>
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" />
            <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" ReadOnly="False"
                UniqueName="OrderID" />
            <telerik:GridBoundColumn HeaderText="EmployeeID" DataField="EmployeeID" UniqueName="EmployeeID" />
            <telerik:GridBoundColumn HeaderText="OrderDate" DataField="OrderDate" UniqueName="OrderDate" />
            <telerik:GridBoundColumn HeaderText="ShipName" DataField="ShipName" UniqueName="ShipName" />
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       string selectQuery = "SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate], [ShipName] FROM [Orders]" ;
       SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery, conn);
       conn.Open();
       adapter1.Fill(datatable1);
       conn.Close();
       RadGrid1.DataSource = datatable1;
   }
 
   protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
      //Code To Update
   }
   protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
   {
      //Code To Insert    
   }
   protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
   {
        //Code To Delete
   }

Thanks,
Princy
0
EIMCM
Top achievements
Rank 1
answered on 05 Aug 2013, 03:30 PM
 Thanks for your response, Princy.

We do regular postbacks for exporting to excel feature. I have raised a support ticket for this issue (Ticket ID : 722878) where I have also attached the source code of the project. Please let me know if you need any additional details.

Regards,
EIMCM.
0
Daniel
Telerik team
answered on 08 Aug 2013, 01:11 PM
Hi,

I will post my answer here so that it is available to the community:

The problem is that there is no way to "ignore the paging" without getting the other pages from the database. If you disable the IgnorePaging property you will get what you see.
There is no way to sidestep the rebind in the original case as the control needs this information in order to export it.

Regards,
Daniel
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.
Tags
Grid
Asked by
EIMCM
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
EIMCM
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or