Export DataList to Excel
Can someone please help. I was able to export my Gridview to Excel, but had to use a datalist instead due to some unique bindings I had to place on the contents.
I tried simply changing "GridView" to "DataList" and it didn't work.
Please help.
Kind Regards,
Rob
Dim MyGridView As New GridView()
'MyGridView = GridView1
MyGridView.DataSource = KnightsDataSource
MyGridView.DataBind()
Dim attachment As String = "attachment; filename=Members.xls"
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim sw As IO.StringWriter = New IO.StringWriter()
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
MyGridView.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
|