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

[Solved] RadGrid Exporting to Excel more records than bound to the grid

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 22 May 2013, 06:01 PM
I have a radgrid that I'm only binding 200 records to regardless of the total record count.  When exporting to Excel, I want to export the entire record set.  In the RadGrid1_ItemCommand event, I'm resetting the parameters for the SQLDataSource that drives the grid and am creating a view with the complete record set.  However, when the export occurs, only 200 records are exported.  How can export the entire set of records?


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 May 2013, 04:48 AM
Hello Matt,

I have tried the export to excel with an example ,it works fine for me.
Please have a look at the code and see if it helps you.

C#:
SqlConnection conn = new SqlConnection(connection);
public SqlCommand SqlCommand = new SqlCommand();
DataTable dt1 = new DataTable();
 
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    string selectQuery1 = "SELECT top 10 [OrderID], [CustomerID], [EmployeeID], [OrderDate], [ShipName] FROM [Orders]";
    SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
    conn.Open();
    adapter1.Fill(dt1);
    conn.Close();
    RadGrid1.DataSource = dt1;
}
  
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        string selectQuery1 = "SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate], [ShipName] FROM [Orders]";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        RadGrid1.DataSource = dt1;
        RadGrid1.DataBind();        
    }
}

Thanks
Princy

Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or