Porting data from dataset to MS Word

You can dump the contents of a data set to word/Excel sheet and dispaly it in the browser.1. Create a new web form and add a DataGrid control onto the form.Righ

ITPro Today

June 20, 2004

1 Min Read
ITPro Today logo

You can dump the contents of a data set to  word/Excel sheet and dispaly it in the browser.

1. Create a new web form and add a DataGrid control onto the form.Right-click on the grid and choose Auto Format from the context menu.

2. In the code behind just add this code in Page Render or Page Load event

 

Dim dataTbl As DataTable = _
CType(Application.Item("MyGridSet"), DataTable) 
Response.ContentType = "application/ms-word"
Response.AddHeader("Content-Disposition", _
      "inline;filename=Porttest.doc")
DataGrid1.DataSource = dt
DataGrid1.DataBind()
DataGrid1.RenderControl(writer)

On the current page provide a  button to navigate to the new page and pass the dataset/datatable to that page.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like