Interesting..
This may be something other than just converting the grid to excel
Couple of more checks/tests you can perform to narrow the problem down.
1. Ensure EnableViewState is set to true on the page that has datagrid
2. In the immediate window check if there's anything at all is in thi
oStringWriter.ToString(
This will narrow the problem to the conversion code. If it has your table in HTML format then it might be a browser problem
3. Try creating a test page that simply has a button and a grid. Clicking on the button export the grid to Excel. Leave all the default settings of the page
Suresh
----- (e-mail address removed) wrote: ----
When I put in your code, exactly as you have it below, I change only th
Private Sub btnconvert_click line, to reflect the button I am using. It's
radio button
The code I have executing follows
Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object
ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChange
Response.Clear(
Response.Buffer = Tru
Response.ContentType = "application/vnd.ms-excel
Response.Charset = "
Me.EnableViewState = Fals
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter(
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = Ne
System.Web.UI.HtmlTextWriter(oStringWriter
Me.ClearControls(DataGrid1
DataGrid1.RenderControl(oHtmlTextWriter
Response.Write(oStringWriter.ToString()
Response.End(
End Su
Private Sub ClearControls(ByVal ctrl As Control
Dim i As Int3
For i = ctrl.Controls.Count - 1 To 0 Step -
ClearControls(ctrl.Controls(i)
Nex
If ctrl.GetType().ToString() <> "TableCell" The
If Not ctrl.GetType().GetProperty("SelectedItem") Is Nothing The
Dim literal As LiteralControl = New LiteralControl(
ctrl.Parent.Controls.Add(literal
Tr
literal.Text
CType(ctrl.Controls.GetType().GetProperty("SelectedItem").GetValue(ctrl
Nothing), System.String
Catc
End Tr
ctrl.Parent.Controls.Remove(ctrl
End I
Els
Dim literal As LiteralControl = New LiteralControl(
ctrl.Parent.Controls.Add(literal
literal.Text
CType(ctrl.Controls.GetType().GetProperty("Text").GetValue(ctrl, Nothing)
System.String
ctrl.Parent.Controls.Remove(ctrl
End I
Retur
End Su
as you can see, it is exactly the same as yours, excluding the sub on th
first line
However, when this runs, I'll step thru it in debug mode, and it'll onl
return a blank page. It appears that it's just empty. Do not know why. I
does appear to iterate thru the loop in the clearcontrols section. When i
gets to response.end though, it just sits there
I'm trying to return a customer list, with names, addresses, etc. on it
Stev
Suresh said:
It's working for me in VB.NET as well
Can you post your code? Maybe some C# wasn't coverted properly
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e A
System.EventArgs) Handles btnConvert.Clic
Response.Clear(
Response.Buffer = Tru
Response.ContentType = "application/vnd.ms-excel
Response.Charset = "
Me.EnableViewState = Fals System.IO.StringWriter(
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = Ne System.Web.UI.HtmlTextWriter(oStringWriter
If Not ctrl.GetType().GetProperty("SelectedItem") Is Nothing Then
Dim literal As LiteralControl = New LiteralControl()
ctrl.Parent.Controls.Add(literal)
Try
literal.Text =
CType(ctrl.Controls.GetType().GetProperty("SelectedItem").GetValue(ctrl,
Nothing), System.String)
Catch
End Try
ctrl.Parent.Controls.Remove(ctrl)
End If
Else
Dim literal As LiteralControl = New LiteralControl()
ctrl.Parent.Controls.Add(literal)
literal.Text =
CType(ctrl.Controls.GetType().GetProperty("Text").GetValue(ctrl, Nothing),
System.String)