Nettiers provides an event that gets called prior to the export called OnExcelBeforeFormat as well as after the export called OnExcelAfterFormat. Our gridview used sorting, paging, and had checkboxes in some columns.
By using this code, I was able to avoid the issue without turning off event validation or messing with the template...
///
/// Replace any of the contained controls with literals
///
///
private static void PrepareControlForExport(Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
Control current = control.Controls[i];
if (current is LinkButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
}
else if (current is ImageButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
}
else if (current is HyperLink)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
}
else if (current is DropDownList)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
}
else if (current is CheckBox)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False")) ;
}
if (current.HasControls())
{
PrepareControlForExport(current);
}
}
}
protected void GridView_OnExcelBeforeFormat(object sender, EventArgs e)
{
PrepareControlForExport(GridView);
}
You will need to specify this event name for the OnExcelAfterFormat property of the EntityGridView. This method could also be used with a standard Gridview just prior to any other export code.
One other thing that I found is that the gridview did not export the filtered results. So, for this I added a piece of code to rebind the search parameters.
On Page_Load when IsPostback = true
//if export link clicked
if (Request.Params.Get("__EVENTTARGET").Contains("lnkExport"))
{
//make sure to rebind search params
GridViewSearchPanel.DataBind();
}
Hope someone else finds this helpful!