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 / DataGrid / July 2003

Tip: Looking for answers? Try searching our database.

How to check if CType(e.Item.DataItem, DataRowView) is DBNULL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob Wire - 29 Jul 2003 20:05 GMT
How do you check if CType(e.Item.DataItem, DataRowView) is
DBNULL?

I have a Datagrid with Edit,Update, and Insert buttons to
a SQL data table.  During an update, a drop down list is
used for one of the fields which defaults to current value
in a row.  

   Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
       If e.Item.ItemType = ListItemType.EditItem Then
           Dim drv As DataRowView = CType
(e.Item.DataItem, DataRowView)
           Dim currentAttachType As String

           currentAttachType = CType(drv("ATTACH_TYPE"),
String)

           Dim ddl As DropDownList
           ddl = CType(e.Item.FindControl
("DropDownList1"), DropDownList)
           ddl.SelectedIndex = ddl.Items.IndexOf
(ddl.Items.FindByText(currentAttachType))
       End If
   End Sub

Insert fails with an error "Cast from type 'DBNull' to
type 'String' is not valid" if this function is used.  
Insert button on click uses the regular update function as
well.

I think an if statement on the drv("ATTACH_TYPE") to check
if it is a DBNULL or not might fix it.  How might you do
this?

Any suggestions?

Thank you,

Rob Wire
andrei - 30 Jul 2003 17:00 GMT
Rob,

currentAttachType = iif(IsDBNull(drv("ATTACH_TYPE")), _

           "", _

           CType(drv("ATTACH_TYPE"), String))

HTH,

Andrei.

> How do you check if CType(e.Item.DataItem, DataRowView) is
> DBNULL?
[quoted text clipped - 38 lines]
>
> Rob Wire
Rick Rainey[MSFT] - 30 Jul 2003 17:24 GMT
Hi Rob,

You can use the IsDbNull function to determine if the value is null.

For Example,

If Not IsDbNull(drv) Then
   'Code to handle this situation.
End If

Hope this helps,

Rick[MSFT]
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note:  For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

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



©2008 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.