PC Review


Reply
Thread Tools Rate Thread

Displaying databound values as members of a collection or array

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      13th Aug 2008
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
(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      13th Aug 2008



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" <(E-Mail Removed)> wrote in message
news:uG$4d6X$(E-Mail Removed)...
>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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      13th Aug 2008

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

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




"sloan" <(E-Mail Removed)> wrote in message
news:OpBDQKY$(E-Mail Removed)...
>
>
>
> 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" <(E-Mail Removed)> wrote in message
> news:uG$4d6X$(E-Mail Removed)...
>>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
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>

>
>



 
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
Displaying databound values as members of a collection or array Nathan Sokalski Microsoft ADO .NET 2 13th Aug 2008 09:28 PM
Client callback adding items to databound collection = crossthread error Steve K. Microsoft C# .NET 1 10th Jan 2008 10:22 AM
Error 1004 when setting a Series Collection.Values as Array via VB =?Utf-8?B?RGF2aWQgTWVzc2VuZ2Vy?= Microsoft Excel Programming 6 8th Jul 2007 10:59 AM
Displaying Databound items in a control =?Utf-8?B?R3VzdHlu?= Microsoft Dot NET 0 26th Dec 2005 11:37 PM
Easiest way to copy values from a collection to an array? Matthias S. Microsoft C# .NET 2 19th Oct 2004 04:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:21 AM.