render failed on inherited DataGrid

Discussion in 'ASP .Net Web Controls' started by Frank, Aug 12, 2004.

  1. Frank

    Frank Guest

    Hi all,

    I want to derive a class from DataGrid so that I can have
    a label on the top.
    But when I tried to add the control to my form, I got an
    error "Specified cast is not valid" on the line:
    MyBase.Render(w) in the Render function.

    Thanks a lot.
    Frank

    Here is my simple code.

    Private Sub Page_Load(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Load

    Dim g As New Grid2
    Me.Form1.Controls.Add(g)
    End Sub
    Public Class Grid2
    Inherits DataGrid
    Dim _label1 As New Label

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
    Me.Controls.Add(Me._label1)
    End Sub
    Public ReadOnly Property Label1() As Label
    Get
    Return Me._label1
    End Get
    End Property
    Protected Overrides Sub Render(ByVal w As
    HtmlTextWriter)
    MyBase.Render(w)
    Me._label1.RenderControl(w)
    End Sub
    End Class
     
    Frank, Aug 12, 2004
    #1
    1. Advertising

  2. Frank

    Josh Guest

    In a similar situation a while back I ended up creating a User-Control
    containing the grid and the other controls. I exposed the Grid itself as a
    public property of the UserControl
     
    Josh, Aug 12, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,119
    Lau Lei Cheong
    May 15, 2004
  2. Frank
    Replies:
    2
    Views:
    1,132
    Scott Allen
    Aug 12, 2004
  3. sck10
    Replies:
    6
    Views:
    957
    sck10
    Sep 1, 2006
  4. Glenn Gillen
    Replies:
    0
    Views:
    320
    Glenn Gillen
    Nov 17, 2006
  5. 7stud --
    Replies:
    11
    Views:
    465
    7stud --
    Nov 9, 2007
Loading...

Share This Page