stephenk1973
Technical User
I have a stored procedure which i use to populate a gridview. Some of the gridview columns have visible set false but on export i make them visible by looping through all the columns. My export button is on the master page, code, ....
Dim gd As New GridView
gd = Me.Page.Controls(0).FindControl("MainFormData").FindControl("Maincontent").FindControl("GridView1")
Dim i As Integer
For i = 0 To (gd.Columns.Count() - 1)
gd.Columns(i).Visible = True
Next i
gd.AllowPaging = False
gd.AllowSorting = False
Response.AddHeader("content-disposition", "attachment;filename=Exp.xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Dim grd As New GridView
Me.Controls.Add(frm)
frm.Controls.Add(gd)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
When i 'programatically create' the datasouce i am running into a problems. Though i can loop thorough the columns making them visible no data shows just blank cells. If the gridview is tied to Sqldatasource this is solved by using databind, when the data source is progrmatically create the databind throws some html into excel (<form name="aspnetForm" method="post" action="SalesSizeAnlaysis.aspx" id="aspnetForm"> etc).
All suggestions appreciated.
Stephen
Dim gd As New GridView
gd = Me.Page.Controls(0).FindControl("MainFormData").FindControl("Maincontent").FindControl("GridView1")
Dim i As Integer
For i = 0 To (gd.Columns.Count() - 1)
gd.Columns(i).Visible = True
Next i
gd.AllowPaging = False
gd.AllowSorting = False
Response.AddHeader("content-disposition", "attachment;filename=Exp.xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Dim grd As New GridView
Me.Controls.Add(frm)
frm.Controls.Add(gd)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
When i 'programatically create' the datasouce i am running into a problems. Though i can loop thorough the columns making them visible no data shows just blank cells. If the gridview is tied to Sqldatasource this is solved by using databind, when the data source is progrmatically create the databind throws some html into excel (<form name="aspnetForm" method="post" action="SalesSizeAnlaysis.aspx" id="aspnetForm"> etc).
All suggestions appreciated.
Stephen