Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C# UserControl Export GridView to Excel troubles

Posted on 2007-10-08
10
Medium Priority
?
4,907 Views
Last Modified: 2013-11-07
Hello,

I have a working export to excel functionality in a standard aspx file. When I try to create the same functionality in a usercontrol i recieve an error:
 no suitable method found to override       
VerifyRenderingInServerForm(System.Web.UI.Control)':

here is the offending function.
public override void   VerifyRenderingInServerForm(Control control)
    {
         
    }
 what has gon wrong here. assistance would be appreciated

thanks

0
Comment
Question by:B_P_B
  • 5
  • 5
10 Comments
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20037100
Member of System.Web.UI.Page
public virtual void VerifyRenderingInServerForm(System.Web.UI.Control control)

Not sure what your trying to do within the above method but it isn't a method of UserControl.  

Are you looking for a replacement for the VerifyRenderingInServerForm method within UserControl?

0
 

Author Comment

by:B_P_B
ID: 20037268
Below is the code that I am trying to install into a usercontrol, but when it runs in the user controll an error appers at compile time - I am not sure of the meaning of the error. I was hoping that someone could help me steer around this problem.  

 protected void Page_Load(object sender, EventArgs e)
    {
         
        GridView1.DataSource = CreateReport();
        GridView1.DataBind();
    }

    ICollection CreateReport()
    {

        DataRow dr;
        DataView dv;
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("test col -1", typeof(string)));
        dt.Columns.Add(new DataColumn("test col -2", typeof(string)));
        dt.Columns.Add(new DataColumn("test col -3", typeof(string)));
        dt.Columns.Add(new DataColumn("test col -4", typeof(string)));
        dr = dt.NewRow();
        for (int i = 0; i <= 10; i++)
        {
            dr = dt.NewRow();
         
            dr[0] = "col-0, Row"+i.ToString();
            dr[1] = "col-1, Row" + i.ToString();
            dr[2] = "col-2, Row" + i.ToString();
            dr[3] = "col-3, Row" + i.ToString();
            dt.Rows.Add(dr);
        }
       
        dv = new DataView(dt);

        return dv;

    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        // do not delete
        // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.

    }

    protected void GridView1_PageIndexChanging(Object sender, GridViewPageEventArgs e)
    {

        GridView1.PageIndex = e.NewPageIndex;

        GridView1.DataSource = CreateReport();
        GridView1.DataBind();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        FontUnit oldfont;
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=" + "whooHoo" + ".xls");
        Response.Charset = "";



        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        // turn off paging
        GridView1.AllowPaging = false;
        GridView1.DataSource = CreateReport();
        GridView1.DataBind();

        oldfont = GridView1.Font.Size;
        GridView1.Font.Size = 12;


        GridView1.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());

        Response.End();

        // turn the paging on again

        GridView1.Font.Size = oldfont;
        GridView1.AllowPaging = true;

        GridView1.AllowPaging = true;
        GridView1.DataSource = CreateReport();
        GridView1.DataBind();

    }
0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20040911
The above code is going into a UserControl that is going to be used in a windows applicaiton?
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:B_P_B
ID: 20041074
no, a web application ...aspx
0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20041150
Have you created a Web User Control or a Web Control Library?
0
 

Author Comment

by:B_P_B
ID: 20041263
My problem is when I try to compile with the function  "public override void VerifyRenderingInServerForm(Control control)" I recieve a "no suitable method found to override" back from the compiler. I have used this code in various other applications and this is my first attempt to incapsulate it in a "UserControl"  
   

   
0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20041701
A User Control is for Windows not Web; should be a .ascx.

Based of the above code just remove the problem method.
public override void VerifyRenderingInServerForm(Control control)
{
    // do not delete
    // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
}

Is not needed.
0
 
LVL 5

Accepted Solution

by:
KPMT-Technician earned 2000 total points
ID: 20041765
public partial class WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load( object sender, EventArgs e )
    {
        ///  .... add your code ...
    }

    private ICollection CreateReport()
    {
        ///  .... add your code ...
    }

    protected void GridView1_PageIndexChanging(Object sender, GridViewPageEventArgs e)
    {
        ///  .... add your code ...
    }

    protected void Button1_Click( object sender, EventArgs e )
    {
                ///  .... add your code ...
     }

    /// This might be what your thinking needs to be in your Web User Control
    protected override void Render( HtmlTextWriter writer )
    {
        /// this is needed to render your new control.
        base.Render( writer );
    }
}
0
 

Author Comment

by:B_P_B
ID: 20112385
Thanks for the answer...I will see if this works for me. Sorry about the delay...just got back after a week off
0
 

Author Comment

by:B_P_B
ID: 20112968
Well your suggestions worked...I do have one other problem how do I set a Command field ShowSelectButton to equal false programmatically? I get an erroron  GridView1.RenderControl(htmlWrite); when the state of the command field is set to true.

<Columns>
            <asp:CommandField ButtonType="Button" HeaderText="Delete" SelectText="Delete" ShowSelectButton="true" />
        </Columns>

 I guess thats a seperate question, but the points are yours for the original question.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question