Hi im developing an asp.net report using vb language. I created the report previously using datagrid,which works well when i click the export button. It downloads the datagrid to excel format. But now i need to add anew header to the report,so i changed to using table which seems as a solution to the problem. I've managed to create the table and produce the report,but now i've to export th etable to excel format same as the one i did for my datagrid. I truied to just modify the code to my table name,but when it downloads, there is only a single empty cell in the excel file.
I paste my code so that anyone could point where is my mistake.
My aspx page

<form id="form1" runat="server">
<table style="width: 600px">
<tr>
<td class="headertext" style="width: 798px" >
SUMMARY REPORT SINGAPORE ( ALL)
</td>
</tr>
<tr><td class="textfont" style="width: 798px; height: 17px;" >
<asp:Label ID="lblMessage" runat="server" Text="Label" Width="264px"></asp:Label></td></tr>
</table>
 
<br />
<asp:Table ID="tblSummAllSg" runat="server" Font-Names="Verdana" BorderWidth="1"
Font-Size="XX-Small">
</asp:Table>
<br />
<br />
 
 
<table align="center">
<tr><td>
<asp:Button ID="btnExport" runat="server" Text="Export As Excel" BorderColor="#C00000" />
</td></tr>
</table>
 
</form>

My code behing page (on page load method)

Dim tableHeading As TableRow = New TableRow()
 
'Create and add the cells that contain the CallDate column heading text.
Dim DateHeading As TableHeaderCell = New TableHeaderCell()
DateHeading.Text = "Call In Date"
DateHeading.HorizontalAlign = HorizontalAlign.Center
tableHeading.Cells.Add(DateHeading)
 
'Create and add the cells that contain the Calls column heading text.
Dim TotalCallHeading As TableHeaderCell = New TableHeaderCell()
TotalCallHeading.Text = "Total Calls"
TotalCallHeading.ColumnSpan = 5
TotalCallHeading.HorizontalAlign = HorizontalAlign.Center
tableHeading.Cells.Add(TotalCallHeading)
Dim tableHeading2 As TableRow = New TableRow()
 
Dim CallInDateHeading As TableCell = New TableCell()
CallInDateHeading.Text = "Call In Date"
CallInDateHeading.HorizontalAlign = HorizontalAlign.Center
tableHeading2.Cells.Add(CallInDateHeading)
Dim InBoundOutBoundHeading As TableCell = New TableCell()
InBoundOutBoundHeading.Text = "InBound/OutBound"
tableHeading2.Cells.Add(InBoundOutBoundHeading)
tblSummAllSg.Rows.Add(tableHeading)
tblSummAllSg.Rows.Add(tableHeading2)
While (objreader.Read())
 
Dim detailsRow As TableRow = New TableRow()
 
Dim CallInDateCell As TableCell = New TableCell()
CallInDateCell.Text = objreader("CallInDate").ToString()
detailsRow.Cells.Add(CallInDateCell)
Dim InBoundOutBoundCell As TableCell = New TableCell()
InBoundOutBoundCell.Text = objreader("InBoundOutBound").ToString()
detailsRow.Cells.Add(InBoundOutBoundCell)
Dim IncompletePrankCell As TableCell = New TableCell()
IncompletePrankCell.Text = objreader("IncompletePrank").ToString()
detailsRow.Cells.Add(IncompletePrankCell)
tblSummAllSg.Rows.Add(detailsRow)
End While

My code behing page (on export button click)

Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
' binding datagrid result to export list
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=DetailReport.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
tblSummAllSg.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub

I really hope someone can help me solve this. Im not sure now if doing this report as table is a solution to the datagrid problem. Im running out of idea and time. Any help is really appreciated. Thank you in advance.

ciao ,

what you need to do is refill your tblsummallsg ....and then call
tblSummAllSg.RenderControl(htmlWrite)

because on click of the button al the data is lost ...

hope it helps...

Gauri

ciao ,

what you need to do is refill your tblsummallsg ....and then call
tblSummAllSg.RenderControl(htmlWrite)

because on click of the button al the data is lost ...

hope it helps...

Gauri

Hi Ciao,

Even i am also facing same problem. Have you solved the problem? Tones of advance thanks if you post your code.

Have a nice weekend

Giri

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.