render failed on inherited DataGrid

F

Frank

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
 
J

Josh

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top