Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / March 2005

Tip: Looking for answers? Try searching our database.

DataGrid subclass - design time problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 04 Mar 2005 16:00 GMT
I created a custom control which is a simple subclass of the DataGrid.  I
wanted to display a message when the DataSource is empty.  Right now I am
assuming the datasource is a datareader.

The problem is in design mode.  I get the error "Error in displaying...".
This is caused by the DataSource override property trying to access the data
source at design time.  How do I set things up to avoid this design time
problem.

Thanks.  Jay

Imports System.ComponentModel

Imports System.Web.UI

Public Class MyDataGrid

Inherits System.Web.UI.WebControls.DataGrid

Public ShowMyHeader As Boolean = True

Public NoDataMessage As String = "No Data Is Available!"

Private HasData As Boolean

'Public Overrides Property DataSource() As Object

' Get

' Return (MyBase.DataSource)

' End Get

' Set(ByVal aDataSource As Object)

' HasData = aDataSource.HasRows

' MyBase.DataSource = aDataSource

' End Set

'End Property

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

If HasData Then

MyBase.Render(writer)

Else

Dim Message As New System.Web.UI.WebControls.Label

Message.Text = NoDataMessage

Message.Font.Bold = True

Message.Font.Size = System.Web.UI.WebControls.FontUnit.Point(10)

Message.Font.Name = "arial"

Message.ForeColor = System.Drawing.Color.Red

Me.ShowHeader = Me.ShowMyHeader

writer.AddAttribute(HtmlTextWriterAttribute.Border, "0")

writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0")

writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0")

writer.RenderBeginTag(HtmlTextWriterTag.Table)

writer.RenderBeginTag(HtmlTextWriterTag.Tr)

writer.AddAttribute(HtmlTextWriterAttribute.Align, "center")

writer.RenderBeginTag(HtmlTextWriterTag.Td)

MyBase.Render(writer)

writer.RenderEndTag() ' Td

writer.RenderEndTag() ' Tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr)

writer.AddAttribute(HtmlTextWriterAttribute.Align, "center")

writer.AddAttribute(HtmlTextWriterAttribute.Valign, "bottom")

writer.AddAttribute(HtmlTextWriterAttribute.Height, "30")

writer.RenderBeginTag(HtmlTextWriterTag.Td)

Message.RenderControl(writer)

writer.RenderEndTag() ' Td

writer.RenderEndTag() ' Tr

writer.RenderEndTag() ' Table

End If

End Sub

End Class
Jay - 04 Mar 2005 19:15 GMT
I found the problem, but not how to solve it.  The problem is with the
following property, and specifically the line: HasData =
aDataSource.HasRows.  Everything works fine in runtime mode.  In design time
I get an error.  If I quote out that line and hard code HasData everything
works fine in design time. Supposedly the If (HttpContext.Current is
DBNull.value) detects desgin time but it does not seem to help

HELP. Jay

Public Overrides Property DataSource() As Object

Get

Return (MyBase.DataSource)

End Get

Set(ByVal aDataSource As Object)

If (HttpContext.Current Is DBNull.Value) Then

HasData = False

Else

'HasData = aDataSource.HasRows

HasData = True

End If

MyBase.DataSource = aDataSource

End Set

End Property

>I created a custom control which is a simple subclass of the DataGrid.  I
>wanted to display a message when the DataSource is empty.  Right now I am
[quoted text clipped - 105 lines]
>
> End Class
Jay - 04 Mar 2005 19:29 GMT
I know have found the solution!

The following statement:
If (HttpContext.Current Is DBNull.Value) Then

should be:
If (HttpContext.Current Is Nothing) Then

I found an article on detecting DesignMode.  It was written in C# and used
(HttpContext.Current == null).  It turns out that you must use NOTHING in
vb.net.

Jay

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.