Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 14th, 2006, 9:34 PM   #1
Mortavitch
Newbie
 
Join Date: Nov 2004
Posts: 14
Rep Power: 0 Mortavitch is on a distinguished road
Exporting a Datagrid to Excel problem

I have been having a little trouble exporting a datagrid into an excel file. The issue at hand is that there is a column in my datagrid that is set up as a LinkButton in a TemplateColumn. When I expot the datagrid into excel I get ever column except for the template column. It just leaves that column blank. I was wondering what I could do to get the column to export into the excel file.

Here is the code for the template column
<asp:TemplateColumn HeaderText="Category" SortExpression="CTGY_NBR">
<HeaderStyle Width="6%"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton Runat="server" ID="lnkCategory"
CommandName="CatDrillDown" CommandArgument='<%#
container.dataitem("CTGY_NBR") %>' >
<%# container.dataitem("CTGY_NBR") %>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

Here is my export function:

Private Sub ImgbtnExport_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgBtnExport.Click
        Dim objExport As New clsDS()
        Try
            If dg.Visible = True Then
                objExport.ExportToExcel(dg, Response, "Weekly Store OOS by Category")
            Else
                objExport.ExportToExcel(dgCtgy, Response, "Weekly Store OOS by Category")
            End If
        Catch ex As Exception
            Handleerror(ex)
        Finally
            objExport = Nothing
        End Try
    End Sub

Public Sub ExportToExcel(ByVal dg As DataGrid, _
                           ByVal aResponse As HttpResponse, _
                           Optional ByVal asFilename As String = "")
        Try
            aResponse.Clear()
            aResponse.ContentType = "application/vnd.ms-excel"
            aResponse.AddHeader("Content-Disposition", "attachment;filename=" & asFilename & ".xls;")
            aResponse.Charset = ""
            Dim tw As New System.IO.StringWriter()
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            dg.GridLines = GridLines.Both
            Me.ClearControls(dg)
            dg.HeaderStyle.Font.Bold = True
            dg.RenderControl(hw)
            dg.GridLines = GridLines.Both
            aResponse.Write(tw.ToString())
            
            aResponse.Flush()
            aResponse.Close()
        Catch err As Exception
            Throw err
        End Try
    End Sub
__________________
It's too bad that stupidity isn't painful
Mortavitch is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi/perl script + IE problem joyceshee Perl 2 Jan 24th, 2006 11:10 AM
entering data into excel from a form glevine Perl 1 Nov 18th, 2005 5:03 PM
How can I disable particular rows in a datagrid? HappyTomato C# 2 Aug 25th, 2005 3:48 PM
Reading Excel files on the web sagi Other Web Development Languages 3 May 2nd, 2005 10:24 AM
How to run a macro in MSProject from Excel? jiancheng80 Visual Basic 2 Jan 19th, 2005 6:49 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC