473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
nj********@hotmail.com
http://www.nathansokalski.com/
Aug 13 '08 #1
2 1003

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" <ns*******@kyledavidgroup.comwrote in message
news:uG**************@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
nj********@hotmail.com
http://www.nathansokalski.com/

Aug 13 '08 #2

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

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


"sloan" <sl***@ipass.netwrote in message
news:Op**************@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" <ns*******@kyledavidgroup.comwrote in message
news:uG**************@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
nj********@hotmail.com
http://www.nathansokalski.com/


Aug 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

74
by: Mark | last post by:
Hello Friends Please check the code below. One in C# and other in VB .Net In C# I am not able to access a static property by an instance variable, but in VB I can do it easily. The Error is ...
2
by: Michael Kellogg | last post by:
I have a collection of objects that I am trying to display in a Windows Forms Datagrid. I have had problems doing this before, so the first time around I went and did a Grid.TableStyles.Clear...
0
by: Matthew87 | last post by:
Hi all I'm having a bit of trouble completeing my coursework basically so far i have created Citenary class with support methods for a private array. The problem is i can add objects to the array...
8
by: Andy B | last post by:
I have the object property StockContract.Dictionary which is a dictionary collection of <string, stringkey/value pairs. I need to be able to retreive the keys and their values and display them on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.