ILearnable .Net

December 8, 2005

Christmas Calendar 8/24

Filed under: Uncategorized — andreakn @ 00:13

What to do when you want to bind more than one field into a dropdownlist?

You’ve created your object,


and you want a Dropdown to contain, say, both the Id property and the Name property.

“DOH” you might say, now I’ve got to create a new property that contains the textual representation of the Id and Name in the object.. “why oh why must my beautiful object depend on the whims of my presentation layer”

fear not ye brave coders. the solution is nigh!

write one of these beauts and you’ll be set.

DropDownList1.DataTextField = MyObject.Id & ā€-ā€ & MyObject.Name;
DropDownList1.DataValueField = MyObject.Id;

The & is not to be confused with && as in “logical AND”. but is more like “AND concatenate THIS!! “


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: