Concatenate Columns

Posts   
 
    
daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 21-Nov-2007 13:50:39   

Hi

If I had three columns in my datbase, and I would like to concatenate them on my databind, how would I do this? It is for a listbox.

For example I have the columns

Car Make Introduced Year Discoontinued Year

In my dropdown I would like it to say:

Fiat Punto (2003-2004)

If it helps, here's my current code:

ResultsetFields fields = new ResultsetFields(1);
            fields.DefineField(CapCdeValFields.LongModelDesc, 0, "LongModelDesc");

            IGroupByCollection groupByClause = new GroupByCollection();
            groupByClause.Add(fields[0]);

            IPredicateExpression filter = new PredicateExpression();
            filter.Add(CapCdeValFields.ManufacturerName == lstMakes.SelectedValue);

            ISortExpression sorter = new SortExpression();
            sorter.Add(new SortClause(CapCdeValFields.LongModelDesc, SortOperator.Ascending));

            TypedListDAO dao = new TypedListDAO();
            dao.GetMultiAsDataTable(fields, dynamicList, 0, sorter, filter, null, false, groupByClause, null, 0, 0);

lstModel.DataSource = dynamicList;
        lstModel.DataTextField = dynamicList.Columns[0].ToString();
        lstModel.DataBind();

Many thanks

Drren

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Nov-2007 15:43:19   

You should use Expressions to append fileds values then set the fields[0].ExpressionToApply with the resultant expression.

Please refer to the manual "Using the generated code -> Field expressions and aggregates"