niall29 Posted October 26, 2004 Posted October 26, 2004 I have a web page with a datagrid of results from a query, then with a press of a button it exports the details to Excel which is working great but I want it when the page loads it automatically turns on Auto filter. Can any one help me with this. Any help would be greatly appreciated. Quote
Tamer_Ahmed Posted November 1, 2004 Posted November 1, 2004 actually i want to know how can u export the data into excel file Quote
niall29 Posted November 4, 2004 Author Posted November 4, 2004 As you can see by my code below I tried a few ideas befor I got it to work see if this helps you or if you need more info I will try yo make in to better English. DataGrid1.DataSource = RDR DataGrid1.DataBind() DataGrid1.Visible = True ' Verify if the page is to be displayed in Excel. If Label1.Text = "1" Then 'Dim xl As New Excel.Application 'Dim wbk As Excel.Workbook 'xl.Visible = True 'wbk = xl.Workbooks.Add 'wbk.Sheets.Add() '' wbk.ActiveSheet.Cells(1, 1).AutoFilter() 'wbk.ActiveSheet.Cells(1, 1).CopyFromRecordset(DataGrid1) ' If Request.QueryString("bExcel") = "1" Then ' Set the content type to Excel. Response.ContentType = "application/vnd.ms-excel" ' Remove the charset from the Content-Type header. Response.Charset = "" Response. ' Turn off the view state. Me.EnableViewState = True Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control. DataGrid1.RenderControl(hw) ' Write the HTML back to the browser. Response.Write(tw.ToString()) ' End the response. Response.End() ' Response.ContentType("A:A")Selected) End If Conn.Close() End Sub Quote
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.