Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Format data column

0 views
Skip to first unread message

aspfun via DotNetMonster.com

unread,
Aug 5, 2009, 12:38:52 PM8/5/09
to
I used code below to export datagrid to Excel. It works fine.
How to format a column (e.g. ds.Tables(0).Columns("Date Paid")) to display a
date format as "mm/dd/yyyy"?

--------------------------
' first let's 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 System.Web.UI.WebControls.DataGrid
' set the datagrid datasource to the dataset passed in
' ds.Tables(0).Columns("Date Paid")

dg.DataSource = ds.Tables(0)

'bind the datagrid
dg.DataBind()

'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'all that's left is to output the html

response.Write(stringWrite.ToString)
response.End()

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-datagrid/200908/1

0 new messages