• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5046
  • Last Modified:

C# UserControl Export GridView to Excel troubles

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
B_P_B
Asked:
B_P_B
  • 5
  • 5
1 Solution
 
KPMT-TechnicianCommented:
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
 
B_P_BAuthor Commented:
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
 
KPMT-TechnicianCommented:
The above code is going into a UserControl that is going to be used in a windows applicaiton?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
B_P_BAuthor Commented:
no, a web application ...aspx
0
 
KPMT-TechnicianCommented:
Have you created a Web User Control or a Web Control Library?
0
 
B_P_BAuthor Commented:
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
 
KPMT-TechnicianCommented:
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
 
KPMT-TechnicianCommented:
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
 
B_P_BAuthor Commented:
Thanks for the answer...I will see if this works for me. Sorry about the delay...just got back after a week off
0
 
B_P_BAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now