fadi Posted March 24, 2004 Posted March 24, 2004 bind the dataset to a grid and set the response type of the page to excel Quote
Bodybag Posted March 24, 2004 Posted March 24, 2004 bind the dataset to a grid and set the response type of the page to excel 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.BackColor = System.Drawing.Color.White 'dg.BorderColor = System.Drawing.Color.White '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 Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.