|
||||
The solution for this is:
Code:
private void btnExportToDoc_Click(object sender, System.EventArgs e)
{
...
...
// Remove unneccessary controls of the Datagrid.
RemoveDatagridControls(dgProdReleaseValid);
// Output the DataGrid control content to the HTML TextWriter.
dgProdReleaseValid.RenderControl(oHtmlTextWriter);
...
...
}
/// <remarks>
/// Note
/// -----
/// This is used to override void VerifyRenderingInServerForm to
/// avoid the below error when "Export to Doc" is clicked
/// as this is a bug reported by MS.
/// http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=e4e08db1-8788-4e58-9e1f-daba86195d9f
///
/// The error message looks like:
/// Server Error in '/PPS' Application.
/// --------------------------------------------------------------------------------
/// Control 'dgProdReleaseValid__ctl2_chkRelease' of type 'CheckBox' must be placed inside a form tag with runat=server.
/// Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
///
/// References:
/// GridView Export to Excel Problems
/// http://geekswithblogs.net/azamsharp/archive/2005/07/25/48213.aspx
/// </remarks>
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered
// for the specified ASP.NET server control at run time.
// No code is required here.
}
/// <summary>
/// Gets the custom date time format as a part of the filename.
/// </summary>
/// <remarks>
/// References:
/// - String Formatting in C#
/// http://blog.stevex.net/index.php/string-formatting-in-csharp/
/// <summary>
/// Removes unneccessary controls of a DataGrid.
/// </summary>
/// <remarks>
/// References:
/// - Extensive Study of GridView Export to Excel (Used by this method)
/// http://www.gridviewguy.com/ArticleDetails.aspx?articleID=197
/// - Export ASP.NET DataGrid to Excel
/// http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp
/// </remarks>
private void RemoveDatagridControls(Control dg)
{
LinkButton lb = new LinkButton();
Literal lit = new Literal();
int i;
for (i = 0; i < dg.Controls.Count; i++)
{
// If LinkButton type is found, remove it.
if (dg.Controls[i].GetType() == typeof(LinkButton))
{
if (dg.Controls[i].Visible)
{
lit.Text = (dg.Controls[i] as LinkButton).Text;
dg.Controls.Remove(dg.Controls[i]);
dg.Controls.AddAt(i, lit);
} // End if.
}
// If DropDownList type is found, remove it.
else if (dg.Controls[i].GetType() == typeof(DropDownList))
{
lit.Text = (dg.Controls[i] as DropDownList).SelectedItem.Text;
dg.Controls.Remove(dg.Controls[i]);
dg.Controls.AddAt(i, lit);
} // End if.
if (dg.Controls[i].HasControls())
{
RemoveDatagridControls(dg.Controls[i]);
} // End if.
} // End for.
}
|
![]() |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| mcmana nak export excel ke mysql | poshberry | Website Programming | 15 | 04-06-2004 04:29 PM |
| can excel VBA 97 be converted to XML? | ymhy_80 | Website Design | 1 | 26-02-2004 01:15 PM |
| convert excel vba to webpage | ymhy_80 | Websites Review and Suggestion | 1 | 20-02-2004 11:50 AM |
| Excel ke MySQL | baddai | Website Programming | 2 | 01-11-2003 10:18 AM |
| Camane nak export flash jadi movie clip ? | myravens | Website Design | 0 | 12-08-2003 05:07 PM |
All times are GMT +8. The time now is 01:53 PM.
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.









Linear Mode

