|
|
|
date: Fri, 29 Aug 2008 12:25:23 -0400,
group: microsoft.public.dotnet.framework.aspnet
back
Re: DataBinding boolean values from a database
Hi Nathan,
I suspect you need to cast it as a boolean and then reverse the logic like
this:
Visible='<%# !(bool)DataBinder.Eval(Container.DataItem,"Discontinued")%>'
Full code below.
Ken
MVP [ASP.NET]
Author: ASP.NET 3.5 For Dummies
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"ProductName") %>'
Visible='<%#
!(bool)DataBinder.Eval(Container.DataItem,"Discontinued")%>'>
</asp:Label><br />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString1 %>"
ProviderName="<%$
ConnectionStrings:NORTHWNDConnectionString1.ProviderName %>"
SelectCommand="SELECT [ProductName], [Discontinued] FROM
[Products]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
"Nathan Sokalski" wrote in message
news:u26SLPfCJHA.4576@TK2MSFTNGP05.phx.gbl...
>I have several controls in an ItemTemplate in a Repeater that will
>sometimes be hidden. I would like to do this by setting the Visible
>property using something like:
> Visible='<%# DataBinder.Eval(Container.DataItem,"deleted") %>'
>
>
>
> However, this is giving me a conversion error. I have tried having the
> database return several different values (the db field is of type bit, but
> I need to use a case statement because Visible is set to the opposite of
> the db field), but still recieve the same error. I know that I can use the
> ItemDataBound event, but would prefer not to since I am simply setting a
> property, not doing any calculations. The database I am using is SQL
> Server 2005, and I am using ASP.NET 2.0. Thanks.
>
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansokalski.com/
>
date: Fri, 29 Aug 2008 14:51:57 -0400
author: Ken Cox
Re: DataBinding boolean values from a database
If 1-col means simply passing back the value of the field, I did try that,
which worked (well, except for the fact that I want the opposite of the
value in the database), which is why I am using a case statement to return
the opposite. This is when the problem started. If Ken's idea of returning
the original value, converting it to a bool, and negating it inline works,
then everything will be great. So hopefully I can make it through this
without resorting to the ItemDataBound event. Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
"John Bell" wrote in message
news:2A533FCC-6224-4C03-B791-0870469B051D@microsoft.com...
>
> "Nathan Sokalski" wrote in message
> news:u26SLPfCJHA.4576@TK2MSFTNGP05.phx.gbl...
>>I have several controls in an ItemTemplate in a Repeater that will
>>sometimes be hidden. I would like to do this by setting the Visible
>>property using something like:
>> Visible='<%# DataBinder.Eval(Container.DataItem,"deleted") %>'
>>
>>
>>
>> However, this is giving me a conversion error. I have tried having the
>> database return several different values (the db field is of type bit,
>> but I need to use a case statement because Visible is set to the opposite
>> of the db field), but still recieve the same error. I know that I can use
>> the ItemDataBound event, but would prefer not to since I am simply
>> setting a property, not doing any calculations. The database I am using
>> is SQL Server 2005, and I am using ASP.NET 2.0. Thanks.
>>
>> Nathan Sokalski
>> njsokalski@hotmail.com
>> http://www.nathansokalski.com/
>
>
> Hi
>
> I assume you are using a case statement in the query behind this? Haave
> you tried using 1-col in the query?
> John
>
>
date: Fri, 29 Aug 2008 17:55:27 -0400
author: Nathan Sokalski
|
|