How To Show a Table In An Excel Spreadsheet?

J

JLuv

What i want to do is take the checked data from a datagrid, send it to
a table, then show that table on an Excel Spreadsheet. Here is a little
bit of my code...

//adminProgress.aspx
<asp:DataGrid ID="pGrid" runat="server" AutoGenerateColumns="false"
AllowSorting="true">
<Columns>
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="check" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="lastName"
HeaderText="Last Name" />
<asp:BoundColumn DataField="firstName"
HeaderText="First Name" />
<asp:BoundColumn DataField="phoneNum"
HeaderText="Work Number" />
</Columns>
</asp:DataGrid>

//code behind to find selected items
private void buildTable()
{
tblTom.ID = "tblSelection";
foreach (DataGridItem dgItem in pGrid.Items)
{

if (((CheckBox)dgItem.FindControl("check")).Checked)
{
TableRow tRow = new TableRow();
TableCell tCell = new TableCell();

tblTom.Rows.Add(tRow);
tRow.Cells.Add(tCell);
tCell.Text = "CHECKED";
//tCell.Text = dSet.Tables[0].Rows[0].ToString();

}
}

//code behind to export from adminProgress.aspx to SpreadSheet.aspx
void export_Click(object sender, EventArgs e)
{
buildTable();
Server.Transfer("SpreadSheet.aspx");

}

//code behind SpreadSheet.aspx to show table from adminProgress.aspx
protected void Page_Load(object sender, EventArgs e)
{
adminProgress progressPage = (adminProgress)Context.Handler;
this.Controls.Add(progressPage.tblTom);
}

What happens is, when i select the wanted names, and click "Export" I
get a prompt to save/open and Excel spreadsheet (which is good). but
the spread sheet is empty(which is bad).
Any help?

oh, i inserted these into the top of SpreadSheet.aspx...
<%@ Reference Page="~/adminProgress.aspx" %>
<% Response.ContentType = "application/vnd.ms-excel"; %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top