Response.Buffer = True Response.ContentType() = "application/vnd.ms-excel" EnableViewState = False dgresultados.AllowPaging = False dgresultados.AllowSorting = False dgresultados.DataBind() Dim tw As System.IO.StringWriter = New System.IO.StringWriter Dim hw As HtmlTextWriter = New HtmlTextWriter(tw) dgresultados.RenderControl(hw) Response.Write(tw.ToString()) Response.End()
private void ClearControls(Control control){for (int i=control.Controls.Count -1; i>=0; i--){ClearControls(control.Controls);}if (!(control is TableCell)){if (control.GetType().GetProperty("SelectedItem") != null){LiteralControl literal = new LiteralControl();control.Parent.Controls.Add(literal);try{literal.Text = (string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);}catch{}control.Parent.Controls.Remove(control);}elseif (control.GetType().GetProperty("Text") != null){LiteralControl literal = new LiteralControl();control.Parent.Controls.Add(literal);literal.Text = (string)control.GetType().GetProperty("Text").GetValue(control,null);control.Parent.Controls.Remove(control);}}return;}