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

How to export grid data to excel file when using simple data - binding?

1 Answer 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 13 Jun 2012, 02:28 AM
Hi telerik team,

Are there any approaches for this case?

Thanks so much!

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 13 Jun 2012, 04:47 AM
Hello Sam,

Try the following code to achieve your scenario.
aspx:
<asp:ScriptManager ID="scriptmanager1" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true" AutoGenerateColumns="false">
  <ExportSettings ExportOnlyData="true"></ExportSettings>
   <MasterTableView CommandItemDisplay="Top">
    <CommandItemSettings ShowExportToExcelButton="true" />
     <Columns>
       <telerik:GridBoundColumn UniqueName="EmployeeID" DataField="EmployeeID"  HeaderText="EmployeeID"></telerik:GridBoundColumn>
       <telerik:GridBoundColumn UniqueName="LastName" DataField="LastName"  HeaderText="LastName"></telerik:GridBoundColumn>
       <telerik:GridBoundColumn UniqueName="FirstName" DataField="FirstName"  HeaderText="FirstName"></telerik:GridBoundColumn>
     </Columns>
   </MasterTableView>
</telerik:RadGrid>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
      SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
      SqlCommand cmd = new SqlCommand("SELECT * FROM [Employees]", con1);
      SqlDataAdapter ad = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      ad.Fill(ds);
      RadGrid1.DataSource = ds;
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or