Concatenating Multiple Data Fields for the DataTextField Property

Many, many times I’ve had the situation where I want to bind a data-set or data-view to a DropDownList, CheckBoxList, or other ListItem-based control, but I need the display text set through the DataTextField property to use multiple data fields from the result set, and not just the 1 field that it is designed to support.

For example, I might have a user’s name separated into 2 distinct data fields: User_Name_First and User_Name_Last, but I want it displayed in the DropDownMenu as “User_Name_Last, User_Name_First”.

Maybe you can relate.  What are the options?

1.  Modify your database query to merge the fields in the SELECT.  This is likely the most efficient solution, but not always the most practical depending on your environment.

2.  Add a new DataColumn to the result set, enumerate through the results, and set the value of the new DataColumn upon each iteration.  Does the job, but not very efficient or elegant.

How about this… go ahead and add a new DataColumn to the result set, but make it an Expression Column.  Example:

oDataSet.Tables(0).Columns.Add(new DataColumn(“MyNewFieldName”, System.Type.GetType(“System.String”), “CurrentField1 + ‘, ‘ + CurrentField2″)

I finally stumbled upon this solution (as simple as it seems) and it is such a relief!  I feel like a goof since it  never occurred to me until now, but its not the first time, and it certainly won’t be the last.  Many online searches yielded several comments on the first 2 options above, but not much else.  Now that I am on this side of the fence, I find it curious as to why there isn’t much discussion on this technique.  Maybe there is a lot of overhead to it?  Not sure, but certainly seems better than iterating through the result set record-by-record.  Seems like a no-brainer to me.

Flash AS2 Tips for Designers, variables in target paths

How can I use a variable in a target path? This may be a well known bit of info for many Flash developers but for this designer who is not code jockey it was a  quite a challenge. I have a flash file that has a movie clip (myclip) attached to it dozens of times, each clip is dynamically named (myclip1, myclip2, myclip3, etc.) and each contains a variable (var_in_myclip) which is loaded from xml. The root contains 2 variables, one is a number (var id:Number;) and the other is a string (var whichclipvar;).

So I need my “whichclipvar” to be the same as one of my “var_in_myclip” in one of “myclip” movie clips and I want to use my “id” number to target a specific “myclip” to get it’s var, like this

whichclipvar = _root.myclip1.var_in_myclip;

But I need the myclip1 in the target path to change if “id” changes.

The solution is to create a new variable that can be used as a string in the target path. Like this:

var myclippath:String=”myclip”+id;

Then use [myclippath] in place of the movie clip in your target path. The square brackets are important for this, and no preceding “.” who knew? The whole code looks like this and requires a movie clip on the stage with an instance name of “myclip” and its symbol properties must be set to export for action script and named “myclip”:

var id:Number;

//// NOTE: the id var can be set in any way that works for your purposes///

var whichclipvar;

var mycontent:XML = new XML();


mycontent.ignoreWhite = true;

mycontent.onLoad = function (success) {

if (success) {

var myxml = this.firstChild;

for (var i=0; i<36; i++) {

myclip.attachMovie(“myclip”, “myclip”+i, (0+i), {var_in_myclip:myxml.firstChild.childNodes[5].childNodes[i].childNodes[1].firstChild.nodeValue,});



var myclippath:String=”myclip”+id;

whichclipvar = _root[myclippath].var_in_myclip;