Advantage of DataValueField

G

Guest

Dear All,

I am actually a bit confused about DataValueField. I know what is the use
of
DataTextField.But dont know anything about DataValue Field.Is it necessary
to use DataValue field whenever we bind any Dropdownbox or listBox.What
if we dont use DataValue field at all and stick with only DataTextField.Has
any 1 encountered any problems when not using DataValueField.What are the
advantages and disadvantages of DataValueField. Any help would be greatly
appreciated.

Cheers,
Sunil Sabir
 
M

MattC

DataValue Field is useful for dynamically populated lists. Usually from
database where each ListItem is matched by an entry in a database with a
unique ID. This was the user can select by picking the Text that they
recognise and then the code would use the Value or ID in this case to
perform its work.


MattC
 
J

Jason Kendall

The DataValueField is there so that, for example, if you have a drop
down list of people's names, you can bind the DataValueField to the
primary key of the 'people' table.


-Jason Kendall
(e-mail address removed)
 
E

Eliyahu Goldin

Sunil,

You should use DataValueField if you need it. Feel free not to use it if you
don't need it.
An example when you need it:
Consider an application where a user should select a country from a dropdown
list. On the screen you would want to show full country name (like
"Russia"). In the database you would want to store the country code (like
"RU"). Let's say you have a table with all country names and codes.You would
want to set DataTextField to the field holding the country name and
DataValueField to the one holding the country code.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top