We help IT Professionals succeed at work.

Webpart problem

MsFox
MsFox asked
on
967 Views
Last Modified: 2008-08-24
Hi,
I am creating a webpart to be used inside Sharepoint using VS 2005.  I am displaying data from an xml file into an SPGridView.  I wanted to export the grid data into a word document via a button click.  In my button click event, I have this code attached.
When I run this, I'm getting an error:
Control 'ctl00_m_g_5a56b8d7_3b36_448e_af53_9f0f4a315c2c__grid' of type 'SPGridView' must be placed inside a form tag with runat=server

For testing, I created a project in VS.Net and put the entire code.  I got the error and search the net and the solution is I need to put:
public override void VerifyRenderingInServerForm(Control control)
{
}
to tell ASP.Net that there is a control that needs to be rendered at runtime.

I can't put this in my webpart  as I got the error no suitable method found to override.  I am getting the error on the part
oGrid.RenderControl(oHtmlTextWriter)

Can you please help me and If this is not possible, are there alternative ways to output grid data to Word.

Thanks a lot.



void print_Click(object sender, EventArgs e)
{
    Context.Response.Clear();
    Context.Response.Buffer = true;
    Context.Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
    //Context.Response.ContentEncoding = System.Text.Encoding.UTF7;
    Context.Response.ContentType = "application/msword";
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
    oGrid.RenderControl(oHtmlTextWriter);
    Context.Response.Output.Write(oStringWriter.ToString());
    Context.Response.Flush();
    Context.Response.End();
 }

Open in new window

Comment
Watch Question

Looks like you need to add an  tag in the .aspx file of your webpart, enclosing the datagrid tag.

Could you post the code from the .aspx file if there's one of these already?

Author

Commented:
Hi,  
Thanks for replying. My webpart application is a class, so it does not have an aspx file.  Plus the controls,  SPGridView and button are  built at runtime.
Thanks.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.