Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Displaying databound values as members of a collection or array (http://www.velocityreviews.com/forums/t630657-displaying-databound-values-as-members-of-a-collection-or-array.html)

Nathan Sokalski 08-13-2008 07:56 PM

Displaying databound values as members of a collection or array
 
I am using databinding and the Repeater control to display the results of a
database query. I normally use the DataBinder.Eval method for this, but in a
scenario I am currently dealing with I would like to be able to do something
like one of the following:


If the value from the database is True then display 'Active', if it is False
display 'Inactive'

OR

Use the value from the database as an index or key to get a value from an
array, collection, or enumeration, which will be the displayed value


I realize that both of these can easily be done using the ItemDataBound
event, but since they are very simple operations I was wondering if there is
a more efficient technique than calling ItemDataBound for every record. Any
ideas? Thanks.

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/



sloan 08-13-2008 08:24 PM

Re: Displaying databound values as members of a collection or array
 



You can create a mini "display value" function on the page code behind.


public string DisplayMyCoolValue( object theValue )
{

if (null== theValue)
{
return string.Empty;
}

bool b = Convert.ToBoolean(theValue);
if(b)
{
return "Active";
}
return "Inactive";

}


notice the "theValue" goes in as on object. That's because of
DataBinder.Eval .

Now just take your DataBinder.Eval , and wrap the function call around
(outside of) it.

DisplayMyCoolValue ( DataBinder.Eval ("ItemActive" )

You'll have to play with it a little, I'm coding from memory.





"Nathan Sokalski" <nsokalski@kyledavidgroup.com> wrote in message
news:uG$4d6X$IHA.3756@TK2MSFTNGP03.phx.gbl...
>I am using databinding and the Repeater control to display the results of a
>database query. I normally use the DataBinder.Eval method for this, but in
>a scenario I am currently dealing with I would like to be able to do
>something like one of the following:
>
>
> If the value from the database is True then display 'Active', if it is
> False display 'Inactive'
>
> OR
>
> Use the value from the database as an index or key to get a value from an
> array, collection, or enumeration, which will be the displayed value
>
>
> I realize that both of these can easily be done using the ItemDataBound
> event, but since they are very simple operations I was wondering if there
> is a more efficient technique than calling ItemDataBound for every record.
> Any ideas? Thanks.
>
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansokalski.com/
>




sloan 08-13-2008 08:28 PM

Re: Displaying databound values as members of a collection or array
 

Here's the call to set the text of a label:

Text='<%# DisplayMyCoolValue(DataBinder.Eval(Container,
"DataItem.ItemActive") )%>'




"sloan" <sloan@ipass.net> wrote in message
news:OpBDQKY$IHA.1296@TK2MSFTNGP02.phx.gbl...
>
>
>
> You can create a mini "display value" function on the page code behind.
>
>
> public string DisplayMyCoolValue( object theValue )
> {
>
> if (null== theValue)
> {
> return string.Empty;
> }
>
> bool b = Convert.ToBoolean(theValue);
> if(b)
> {
> return "Active";
> }
> return "Inactive";
>
> }
>
>
> notice the "theValue" goes in as on object. That's because of
> DataBinder.Eval .
>
> Now just take your DataBinder.Eval , and wrap the function call around
> (outside of) it.
>
> DisplayMyCoolValue ( DataBinder.Eval ("ItemActive" )
>
> You'll have to play with it a little, I'm coding from memory.
>
>
>
>
>
> "Nathan Sokalski" <nsokalski@kyledavidgroup.com> wrote in message
> news:uG$4d6X$IHA.3756@TK2MSFTNGP03.phx.gbl...
>>I am using databinding and the Repeater control to display the results of
>>a database query. I normally use the DataBinder.Eval method for this, but
>>in a scenario I am currently dealing with I would like to be able to do
>>something like one of the following:
>>
>>
>> If the value from the database is True then display 'Active', if it is
>> False display 'Inactive'
>>
>> OR
>>
>> Use the value from the database as an index or key to get a value from an
>> array, collection, or enumeration, which will be the displayed value
>>
>>
>> I realize that both of these can easily be done using the ItemDataBound
>> event, but since they are very simple operations I was wondering if there
>> is a more efficient technique than calling ItemDataBound for every
>> record. Any ideas? Thanks.
>>
>> Nathan Sokalski
>> njsokalski@hotmail.com
>> http://www.nathansokalski.com/
>>

>
>





All times are GMT. The time now is 03:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.