PC Review


Reply
Thread Tools Rate Thread

Conversion from type 'DBNull' to type 'String' is not valid

 
 
Cirene
Guest
Posts: n/a
 
      18th Jun 2008
I'm setting a databound label's backcolor and forecolor like this...

<asp:Label ID="lblSampleColorScheme" runat="server"

BackColor='<%#
System.Drawing.Color.FromName(Eval("AttachmentEntityBackColor")) %>'
Font-Bold="True"

ForeColor='<%#
System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")) %>'
Text="CURRENT COLOR SCHEME"></asp:Label>


The problem is when the value is NULL. I get the above error. How can I
say, if it's null in the db then use "#ffffff"?

Thanks!


 
Reply With Quote
 
 
 
 
Cirene
Guest
Posts: n/a
 
      18th Jun 2008
This doesn't seem to work...

<asp:Label ID="lblSampleColorScheme" runat="server"

BackColor='<%# iif(eval("AttachmentEntityBackColor").equals(DBNull.value),
"#ffffff", System.Drawing.Color.FromName(Eval("AttachmentEntityBackColor")))
%>' Font-Bold="True"

ForeColor='<%# iif(eval("AttachmentEntityForeColor").equals(DBNull.value),
"#000000", System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")))
%>' Text="CURRENT COLOR SCHEME"></asp:Label>


"Cirene" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm setting a databound label's backcolor and forecolor like this...
>
> <asp:Label ID="lblSampleColorScheme" runat="server"
>
> BackColor='<%#
> System.Drawing.Color.FromName(Eval("AttachmentEntityBackColor")) %>'
> Font-Bold="True"
>
> ForeColor='<%#
> System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")) %>'
> Text="CURRENT COLOR SCHEME"></asp:Label>
>
>
> The problem is when the value is NULL. I get the above error. How can I
> say, if it's null in the db then use "#ffffff"?
>
> Thanks!
>



 
Reply With Quote
 
nick chan
Guest
Posts: n/a
 
      19th Jun 2008
u can't use IIF()
System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")) will
still be executed, resulting in error

(IIF is not equaivalent to C's '?' command)

u need to write another function

public function BackColor(AColor as Object) as String
if typeof AColor is DBNull then
return "#FFFFFF"
else
return System.Drawing.Color.FromName(AColor)
end if
end function

BackColor='<%#BackColor(eval("AttachmentEntityBackColor"))%>'

On Jun 19, 5:33*am, "Cirene" <cir...@nowhere.com> wrote:
> This doesn't seem to work...
>
> <asp:Label ID="lblSampleColorScheme" runat="server"
>
> BackColor='<%# iif(eval("AttachmentEntityBackColor").equals(DBNull.value),
> "#ffffff", System.Drawing.Color.FromName(Eval("AttachmentEntityBackColor")))
> %>' Font-Bold="True"
>
> ForeColor='<%# iif(eval("AttachmentEntityForeColor").equals(DBNull.value),
> "#000000", System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")))
> %>' Text="CURRENT COLOR SCHEME"></asp:Label>
>
> "Cirene" <cir...@nowhere.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > I'm setting a databound label's backcolor and forecolor like this...

>
> > <asp:Label ID="lblSampleColorScheme" runat="server"

>
> > BackColor='<%#
> > System.Drawing.Color.FromName(Eval("AttachmentEntityBackColor")) %>'
> > Font-Bold="True"

>
> > ForeColor='<%#
> > System.Drawing.Color.FromName(Eval("AttachmentEntityForeColor")) %>'
> > Text="CURRENT COLOR SCHEME"></asp:Label>

>
> > The problem is when the value is NULL. *I get the above error. *Howcan I
> > say, if it's null in the db then use "#ffffff"?

>
> > Thanks!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from type 'DBNull' to type 'String' is not valid Chris Microsoft ASP .NET 2 11th May 2006 09:20 AM
conversion from type 'DBNull' to type 'float' is not valid ibiza Microsoft ASP .NET 2 27th Jan 2006 09:57 PM
Cast from type 'DBNull' to type 'String' is not valid. tshad Microsoft ASP .NET 6 15th Dec 2004 05:10 PM
Cast from type 'DBNull' to type 'String' is not valid. =?Utf-8?B?RGF2ZSBCeXJvbg==?= Microsoft Dot NET 3 3rd Sep 2004 07:15 AM
Cast from type 'DBNull' to type 'String' is not valid. when creating dataset troutbum Microsoft ADO .NET 5 13th Mar 2004 01:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:32 AM.