[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Return boolean from DataBinder.Eval( whenever it evalutes to DBNULL

Posted on 2009-02-16
7
Medium Priority
?
3,007 Views
Last Modified: 2013-11-07
Within an ascx file, the following code is used to determine whether a checkbox should be enabled
Enabled='<%# IIf(DataBinder.Eval(Container, "DataItem.IsCurrent")=True,True,False)%>'

It works find for editing existing data but errors with Operator '=' is not defined for type 'DBNull' and type 'Boolean'.
How can I check for DBNull and, if true, set Enabled to False?

Thank you.
<asp:CheckBox ID="cbIsCurrent" runat="server" Enabled='<%# IIf(DataBinder.Eval(Container, "DataItem.IsCurrent")=True,True,False)%>'
                   Checked='<%# DataBinder.Eval( Container, "DataItem.IsCurrent") %>' />

Open in new window

0
Comment
Question by:RichardKline
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23655756
If ('value' Is Nothing OrElse IsDBNull('value')) Then
0
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23655764
If  IsDbNull('variable') = False
0
 
LVL 27

Accepted Solution

by:
nmarun earned 2000 total points
ID: 23655808

<asp:CheckBox ID="cbIsCurrent" runat="server" Enabled='<%# GetIsCurrent(DataBinder.Eval(Container, "DataItem.IsCurrent").ToString)%>'
                   Checked='<%# DataBinder.Eval( Container, "DataItem.IsCurrent") %>' />
 
 
public bool GetIsCurrent(isItemCurrent as string)
{
    Dim blnIsCurrent as bool = False
    if (IsDbNull(isItemCurrent)) Then
        blnIsCurrent = False
    else
       if (isItemCurrent = "True") Then
          blnIsCurrent = True
       else
          blnIsCurrent = False
       end if
    end if
    return blnIsCurrent
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:RichardKline
ID: 23655887
nmarun,
Where should the GetIsCurrent function be placed?  
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23655903
In your code-behind file.
0
 
LVL 1

Author Comment

by:RichardKline
ID: 23656081
Thanks!
I came up with this variant: as "enabled" really needs to be the opposite of "checked".   Also to treat DataBinder.Eval(Container, "DataItem.IsCurrent") as an object rather than a string.
ASCX:
            <asp:CheckBox ID="cbIsCurrent" runat="server"
            Enabled='<%# GetIsCurrent(DataBinder.Eval(Container, "DataItem.IsCurrent"), True)%>'
            Checked='<%# GetIsCurrent(DataBinder.Eval(Container, "DataItem.IsCurrent"), False)%>'
            />
Code Behind:
    Public Function GetIsCurrent(ByVal isItemCurrent As Object, ByVal ReverseIt As Boolean) As String
        Dim strIsCurrent As String = "False"
        If Not (IsDBNull(isItemCurrent)) Then
            If isItemCurrent Then
                strIsCurrent = "True"
            End If
        End If
        If ReverseIt Then
            If strIsCurrent.ToLower.StartsWith("f") Then
                strIsCurrent = "True"
            Else
                strIsCurrent = "False"
            End If
        End If
        Return strIsCurrent
     End Function
0
 
LVL 1

Author Closing Comment

by:RichardKline
ID: 31547620
Please see below for the final code version.
Thanks!.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question