467,915 Members | 1,147 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

How To Show a Table In An Excel Spreadsheet?

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"; %>

Jun 28 '06 #1
  • viewed: 1376
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matthew | last post: by
9 posts views Thread by dba123 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.