Jump to content
Xtreme .Net Talk

Exporting multiple GridViews to single/multiple Excel sheets


Recommended Posts

Posted

Hello everybody.

 

1. How can multiple GridViews on a single page be exported to a single Excel file, so that all GridViews are located on the same worksheet (with proper distances - empty rows and columns - between the separate GridViews, of course)?

 

2. How can be done a similar operation: each GridView to be located in a different worksheet but still in a single file?

 

Thank you.

Posted

hi,

 

i have put information in a excel sheet like this:

 

<html>
 <head>
   <title>List</title>

 </head>
 <body>

   <form id="Form1" method="post" runat="server">
   
<%Response.Clear();%>

<table border="1">

<asp:Repeater id="rptRanking" runat="server">
  <HeaderTemplate>      
        <tr>
           <th>Name</th>
           <th>Email</th>
           <th>MobilePhone</th>
           <th>Points</th>
        </tr>
  </HeaderTemplate>
  <ItemTemplate>
     <tr>
       <td><%# DataBinder.Eval(Container.DataItem, "name") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "email") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "phone") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "points") %></td>
     </tr>
  </ItemTemplate>
</asp:Repeater>

</table>

<%Response.End();%>


    </form>

 </body>
</html>
[/html]

 

 

in the codebehind i just put the following

 

[csharp]

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

 

namespace PTCom.PTWiFi.MemberGetMember.Presentation

{

public class Ranking_excel_list : Page

{

protected Repeater rptRanking;

 

private void Page_Load(object sender, EventArgs e)

{

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("content-disposition","attachment; filename=freepromocode_list.xls");

rptRanking.DataSource = "GET INFORMATION FROM DATA SOURCE"

rptRanking.DataBind();

}

 

}

[/csharp]

 

 

hope this helps

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...