inherited DataGrid failed to render

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
 

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,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top