1

I have developed an asp.net control that inherits from the gridview and its called gridviewex... i need some page navigation stuff to render underneath it for some custom paging that i am implenting.. All going well but i can't seem to add new controls to the controls..

For example what i wanted to do is add a asp.net Panel underneath the grid and than add linkbuttons to the panel.

I have this so far but it gives an error

  Unable to cast object of type 'System.Web.UI.WebControls.Panel' to type 
  'System.Web.UI.WebControls.Table'.

The code..

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        Panel uxGridViewNavigation = new Panel();

        LinkButton linkButton = null;

        linkButton = new LinkButton();
        linkButton.Text = "First";
        linkButton.Click += new EventHandler(linkButton_Click);

        uxGridViewNavigation.Controls.Add(linkButton);

        this.Controls.Add(uxGridViewNavigation);

     }

I would really appreciated any help. Its my first server control extension :-)

Thanks

Martin
  • 23,844
  • 55
  • 201
  • 327
  • I have never done a server control extension, but have you tried using the `ShowFooter` property of the GridView and then adding the controls to the last row (which is the footer row)? – Matthew Jones Nov 17 '10 at 16:29
  • Thanks Matthew, but i really need to extend it ... as i need to do more things with it too :-) – Martin Nov 17 '10 at 16:32

1 Answers1

2

Override Render like:

override Render(HtmlTextWriter writer)
{
    // outputs all the inner magic of your grid
    base.Render(writer);

    Panel panel = new Panel();
    // do magic

    // now also render the panel to the writer
    panel.RenderControl(writer);
}
Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120