-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Sudha0829
Message 4 in Discussion




Hi everybody,

 i was trying to export data from datagrid to excel.
I tried following  coding as below, but this doesn't work for me, since my 
datagrid has
paging and sorting option. I am not able to solve this problem, if any one knows
how to solve this, plz suggest me.

Public Shared Sub DataGridToExcel(ByVal dgExport As DataGrid, ByVal response As 
HttpResponse)

'clean up the response.object

response.Clear()

response.Charset = ""

'set the response mime type for excel

response.ContentType = "application/vnd.ms-excel"

'create a string writer

Dim stringWrite As New System.IO.StringWriter

'create an htmltextwriter which uses the stringwriter

Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

'instantiate a datagrid

Dim dg As New DataGrid

' just set the input datagrid = to the new dg grid

dg = dgExport

' I want to make sure there are no annoying gridlines

dg.GridLines = GridLines.None

' Make the header text bold

dg.HeaderStyle.Font.Bold = True

' If needed, here's how to change colors/formatting at the component level

'dg.HeaderStyle.ForeColor = System.Drawing.Color.Black

'dg.ItemStyle.ForeColor = System.Drawing.Color.Black

dg.AllowPaging = False

'bind the modified datagrid

dg.DataBind()

'tell the datagrid to render itself to our htmltextwriter

dg.RenderControl(htmlWrite)

'output the html

response.Write(stringWrite.ToString)

response.End()

End Sub

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnExport.Click

cmpDataGridToExcel.DataGridToExcel(dgToExport, Response)

End Sub

Thanks.

Sudha

                Do you Yahoo!?
 
Take Yahoo! Mail with you! Get it on your mobile phone.

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to