i have an ecport to excel button that i need to have open in a new window with paging turned off so that the export will fill all the results from my datagrid.
here is my code
[code]
private void BtnExport_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gridPhysician.AllowPaging= false;
this.ClearControls(gridPhysician);
gridPhysician.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
private void ClearControls(Control ctrl)
{
for (int i=ctrl.Controls.Count -1; i>=0; i--)
{
ClearControls(ctrl.Controls[i]);
}
if (!(ctrl is TableCell))
{
if (ctrl.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
ctrl.Parent.Controls.Add(literal);
try
{
literal.Text = (string)ctrl.GetType().GetProperty("SelectedItem").GetValue(ctrl,null);
}
catch
{
}
ctrl.Parent.Controls.Remove(ctrl);
}
else
if (ctrl.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
ctrl.Parent.Controls.Add(literal);
literal.Text = (string)ctrl.GetType().GetProperty("Text").GetValue(ctrl,null);
ctrl.Parent.Controls.Remove(ctrl);
}
}
return;
}
[/code]
anythoughts on this...im using a standard asp button
<asp:Button id="Button1" runat="server" Text="Export to Excel"
OnClick="BtnExport_Click" ></asp:Button>