question for the minds

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is what should be an easy question, but I can't get it through my head.
Can someone help me undestand the following?

The way I see it, .DataSource is whatever you decide to refer back to thel
the Datalist in my case it is an array:

System.Collections.ArrayList al = new ArrayList();

DropDownLIst1.DataBind(); is the call that I have to bind my fields that is
an easy one, but for the life of me I DON'T GET:

DropDownList1.DataTextField="Name";
DropDownList1.DataValueField="ID";

It doesn't make sense to me what the difference is for DataTExtField and
DataValueField. It seems that it doesn't matter one way or another, can
someone help me understand?

Provided below are all of the items but my question only lies in the ones
marked Q:


DropDownList1.DataSource=al;
Question: DropDownList1.DataTextField="Name";
Question: DropDownList1.DataValueField="ID";
DropDownList1.DataBind();
 
There is a difference between what the user sees for each item, and the
value it can have. For example, status codes stored in the database could be
A and I, but the user might need to see Active and Inactive for the
descriptions.

This is telling the list which column to use for the description, and which
to use for the value.
 
I like to think of it as one field the user needs, the other field is what
your app needs. Typically the ID is a primary key that will be passed to
another control for selection or maybe back to the database as a foreign key
during an Insert.
 
Back
Top