Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Checkbox = null, Specified cast is not valid.

Reply
Thread Tools

Checkbox = null, Specified cast is not valid.

 
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-25-2007

<edititemtemplate>
<asp:CheckBox ID="giChkBox_bln_removed" runat="server" Checked='<%#
Bind("bln_removed")%>'></asp:CheckBox>
</edititemtemplate>

The above line gives an error (Specified cast is not valid.) if the field
bln_removed is null. Without changing the SQL select statement how can we fix
this?


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-25-2007
On Oct 25, 10:58 pm, rkbnair <(E-Mail Removed)> wrote:
> <edititemtemplate>
> <asp:CheckBox ID="giChkBox_bln_removed" runat="server" Checked='<%#
> Bind("bln_removed")%>'></asp:CheckBox>
> </edititemtemplate>
>
> The above line gives an error (Specified cast is not valid.) if the field
> bln_removed is null. Without changing the SQL select statement how can we fix
> this?


In C#:

<%# Bind("bln_removed")==DBNull.Value ? "" : Bind("bln_removed") %>

In VB.NET:

<%# IIf(IsDBNull(Bind("bln_removed")), "", Bind("bln_removed")) %>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-25-2007
Thanks for the reply.

I tried the C# code that you have given. It is still giving the same error.

--
test


"Alexey Smirnov" wrote:

> On Oct 25, 10:58 pm, rkbnair <(E-Mail Removed)> wrote:
> > <edititemtemplate>
> > <asp:CheckBox ID="giChkBox_bln_removed" runat="server" Checked='<%#
> > Bind("bln_removed")%>'></asp:CheckBox>
> > </edititemtemplate>
> >
> > The above line gives an error (Specified cast is not valid.) if the field
> > bln_removed is null. Without changing the SQL select statement how can we fix
> > this?

>
> In C#:
>
> <%# Bind("bln_removed")==DBNull.Value ? "" : Bind("bln_removed") %>
>
> In VB.NET:
>
> <%# IIf(IsDBNull(Bind("bln_removed")), "", Bind("bln_removed")) %>
>
>

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-25-2007
On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> Thanks for the reply.
>
> I tried the C# code that you have given. It is still giving the same error.
>


Ah, I think it's not because of null, but because of "" in my code

<%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>

 
Reply With Quote
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-26-2007
Alexey,

I'm still getting the same error message.
However, I tried the following code. It works. But the data is not updated
when I save the GridView control.

Checked='<%#
(DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart().TrimEnd()=="True"?true: false) %>'

How can we make the data saved back to the database.
--
test


"Alexey Smirnov" wrote:

> On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > Thanks for the reply.
> >
> > I tried the C# code that you have given. It is still giving the same error.
> >

>
> Ah, I think it's not because of null, but because of "" in my code
>
> <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>
>
>

 
Reply With Quote
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-26-2007
Alexey,
I removed the excess spaces in between the characters. And it works now!!!

Checked=<%#
Bind("bln_core_asset")==DBNull.Value?false:Bind("b ln_core_asset") %>

Thank you very very much for the help.
--
test


"rkbnair" wrote:

> Alexey,
>
> I'm still getting the same error message.
> However, I tried the following code. It works. But the data is not updated
> when I save the GridView control.
>
> Checked='<%#
> (DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart().TrimEnd()=="True"?true: false) %>'
>
> How can we make the data saved back to the database.
> --
> test
>
>
> "Alexey Smirnov" wrote:
>
> > On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > > Thanks for the reply.
> > >
> > > I tried the C# code that you have given. It is still giving the same error.
> > >

> >
> > Ah, I think it's not because of null, but because of "" in my code
> >
> > <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>
> >
> >

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-27-2007
On Oct 26, 3:27 pm, rkbnair <(E-Mail Removed)> wrote:
> Alexey,
> I removed the excess spaces in between the characters. And it works now!!!
>
> Checked=<%#
> Bind("bln_core_asset")==DBNull.Value?false:Bind("b ln_core_asset") %>
>
> Thank you very very much for the help.
> --
> test
>
>
>
> "rkbnair" wrote:
> > Alexey,

>
> > I'm still getting the same error message.
> > However, I tried the following code. It works. But the data is not updated
> > when I save the GridView control.

>
> > Checked='<%#
> > (DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart(*).TrimEnd()=="True"?true :false) %>'

>
> > How can we make the data saved back to the database.
> > --
> > test

>
> > "Alexey Smirnov" wrote:

>
> > > On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > > > Thanks for the reply.

>
> > > > I tried the C# code that you have given. It is still giving the same error.

>
> > > Ah, I think it's not because of null, but because of "" in my code

>
> > > <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>- Hide quoted text -

>
> - Show quoted text -


Glad, that it works. The Checked property's value must be boolean,
meaning it expects a value of either true or false and not spaces, or
other extra characters...

 
Reply With Quote
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-30-2007
Alexey,

The error started appearing again. To my surprise, it was working before.

<edititemtemplate>
<asp:CheckBox ID="geChkBox_bln_core_asset" runat="server"
Checked=<%#Bind("bln_core_asset")==DBNull.Value?fa lse:Bind("bln_core_asset")
%>></asp:CheckBox>
</edititemtemplate>

--
test


"Alexey Smirnov" wrote:

> On Oct 26, 3:27 pm, rkbnair <(E-Mail Removed)> wrote:
> > Alexey,
> > I removed the excess spaces in between the characters. And it works now!!!
> >
> > Checked=<%#
> > Bind("bln_core_asset")==DBNull.Value?false:Bind("b ln_core_asset") %>
> >
> > Thank you very very much for the help.
> > --
> > test
> >
> >
> >
> > "rkbnair" wrote:
> > > Alexey,

> >
> > > I'm still getting the same error message.
> > > However, I tried the following code. It works. But the data is not updated
> > > when I save the GridView control.

> >
> > > Checked='<%#
> > > (DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart(-).TrimEnd()=="True"?true:false) %>'

> >
> > > How can we make the data saved back to the database.
> > > --
> > > test

> >
> > > "Alexey Smirnov" wrote:

> >
> > > > On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > > > > Thanks for the reply.

> >
> > > > > I tried the C# code that you have given. It is still giving the same error.

> >
> > > > Ah, I think it's not because of null, but because of "" in my code

> >
> > > > <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>- Hide quoted text -

> >
> > - Show quoted text -

>
> Glad, that it works. The Checked property's value must be boolean,
> meaning it expects a value of either true or false and not spaces, or
> other extra characters...
>
>

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-30-2007
On Oct 30, 5:29 pm, rkbnair <(E-Mail Removed)> wrote:
> Alexey,
>
> The error started appearing again. To my surprise, it was working before.
>
> <edititemtemplate>
> <asp:CheckBox ID="geChkBox_bln_core_asset" runat="server"
> Checked=<%#Bind("bln_core_asset")==DBNull.Value?fa lse:Bind("bln_core_asset"*)
> %>></asp:CheckBox>
> </edititemtemplate>
>
> --
> test
>
>
>
> "Alexey Smirnov" wrote:
> > On Oct 26, 3:27 pm, rkbnair <(E-Mail Removed)> wrote:
> > > Alexey,
> > > I removed the excess spaces in between the characters. And it works now!!!

>
> > > Checked=<%#
> > > Bind("bln_core_asset")==DBNull.Value?false:Bind("b ln_core_asset") %>

>
> > > Thank you very very much for the help.
> > > --
> > > test

>
> > > "rkbnair" wrote:
> > > > Alexey,

>
> > > > I'm still getting the same error message.
> > > > However, I tried the following code. It works. But the data is not updated
> > > > when I save the GridView control.

>
> > > > Checked='<%#
> > > > (DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart(*-).TrimEnd()=="True"?true:false) %>'

>
> > > > How can we make the data saved back to the database.
> > > > --
> > > > test

>
> > > > "Alexey Smirnov" wrote:

>
> > > > > On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > > > > > Thanks for the reply.

>
> > > > > > I tried the C# code that you have given. It is still giving the same error.

>
> > > > > Ah, I think it's not because of null, but because of "" in my code

>
> > > > > <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>- Hide quoted text -

>
> > > - Show quoted text -

>
> > Glad, that it works. The Checked property's value must be boolean,
> > meaning it expects a value of either true or false and not spaces, or
> > other extra characters...- Hide quoted text -

>
> - Show quoted text -


Are you sure that it occurs exactly here? The code looks good.

Try to delete

Checked=<%#Bind("bln_core_asset")==DBNull.Value?
false:Bind("bln_core_asset"*)

to see if it helps

 
Reply With Quote
 
=?Utf-8?B?cmtibmFpcg==?=
Guest
Posts: n/a
 
      10-30-2007
Yes, it appears at the same place.
--
test


"Alexey Smirnov" wrote:

> On Oct 30, 5:29 pm, rkbnair <(E-Mail Removed)> wrote:
> > Alexey,
> >
> > The error started appearing again. To my surprise, it was working before.
> >
> > <edititemtemplate>
> > <asp:CheckBox ID="geChkBox_bln_core_asset" runat="server"
> > Checked=<%#Bind("bln_core_asset")==DBNull.Value?fa lse:Bind("bln_core_asset"-)
> > %>></asp:CheckBox>
> > </edititemtemplate>
> >
> > --
> > test
> >
> >
> >
> > "Alexey Smirnov" wrote:
> > > On Oct 26, 3:27 pm, rkbnair <(E-Mail Removed)> wrote:
> > > > Alexey,
> > > > I removed the excess spaces in between the characters. And it works now!!!

> >
> > > > Checked=<%#
> > > > Bind("bln_core_asset")==DBNull.Value?false:Bind("b ln_core_asset") %>

> >
> > > > Thank you very very much for the help.
> > > > --
> > > > test

> >
> > > > "rkbnair" wrote:
> > > > > Alexey,

> >
> > > > > I'm still getting the same error message.
> > > > > However, I tried the following code. It works. But the data is not updated
> > > > > when I save the GridView control.

> >
> > > > > Checked='<%#
> > > > > (DataBinder.Eval(Container.DataItem,"bln_core_asse t").ToString().TrimStart(--).TrimEnd()=="True"?true:false) %>'

> >
> > > > > How can we make the data saved back to the database.
> > > > > --
> > > > > test

> >
> > > > > "Alexey Smirnov" wrote:

> >
> > > > > > On Oct 26, 12:08 am, rkbnair <(E-Mail Removed)> wrote:
> > > > > > > Thanks for the reply.

> >
> > > > > > > I tried the C# code that you have given. It is still giving the same error.

> >
> > > > > > Ah, I think it's not because of null, but because of "" in my code

> >
> > > > > > <%# Bind("bln_removed")==DBNull.Value ? false : Bind("bln_removed") %>- Hide quoted text -

> >
> > > > - Show quoted text -

> >
> > > Glad, that it works. The Checked property's value must be boolean,
> > > meaning it expects a value of either true or false and not spaces, or
> > > other extra characters...- Hide quoted text -

> >
> > - Show quoted text -

>
> Are you sure that it occurs exactly here? The code looks good.
>
> Try to delete
>
> Checked=<%#Bind("bln_core_asset")==DBNull.Value?
> false:Bind("bln_core_asset"-)
>
> to see if it helps
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Error: specified cast is not valid. Why not? Alan Silver ASP .Net 5 02-15-2005 08:08 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
I get the following error ( Specified cast is not valid ) with Server.Transfer Andrew ASP .Net 0 08-12-2003 08:26 PM
System.InvalidCastException: Specified cast is not valid. Arjen ASP .Net 1 08-06-2003 03:26 AM
System.InvalidCastException: Specified cast is not valid Floela ASP .Net 3 07-10-2003 10:36 AM



Advertisments