DataTextFormatString from multiple sources

Posts   
 
    
el_manolos
User
Posts: 4
Joined: 17-Mar-2006
# Posted on: 08-Sep-2006 16:11:17   

Hi,

I have this problem. I want to have a drop-down which will have as text: the name of a depot and the description of that depot. E.G. Depot 01/ Lake Central Depot 02/ Germany

I have created this function to make the binding:

private void BindDdSource() { DepotCollection depots = new DepotCollection(); IPredicateExpression filter = new PredicateExpression(); filter.Add(PredicateFactory.CompareValue(DepotFieldIndex.ID, ComparisonOperator.NotEqual,ConfigurationSettings.AppSettings["DrugDestructionFacilityID"].ToString())); ISortExpression sorter = new SortExpression(SortClauseFactory.Create(DepotFieldIndex.ID, SortOperator.Ascending)); depots.GetMulti(filter,0,sorter);

        this.DdSource.DataSource = depots;
        this.DdSource.DataTextField = "ID";
        this.DdSource.DataValueField = "ID";
        this.DdSource.DataTextFormatString = "Depot: {0}";
        this.DdSource.DataBind();
    }

But I don't know how to define the DataTextFormatString or some other parameter to make this work on the fly? Is this possible to make it work on the fly or I just have to this manually?

Thanks, MM

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Sep-2006 16:35:02   

I don't know if you can add the description to the displayed text or not.

But you may workaround this by defining a custom property in your entity that returns the string you want, then you might use this property as the dataTextField of the dropdownList. It should look like the following

public string DisplayText
{
 get { return "Depot" + ID + " / " + Description;}  // use ToString() if ID is not a string.
}
el_manolos
User
Posts: 4
Joined: 17-Mar-2006
# Posted on: 08-Sep-2006 18:51:59   

Walaa wrote:

I don't know if you can add the description to the displayed text or not.

But you may workaround this by defining a custom property in your entity that returns the string you want, then you might use this property as the dataTextField of the dropdownList. It should look like the following

public string DisplayText
{
 get { return "Depot" + ID + " / " + Description;}  // use ToString() if ID is not a string.
}

I understand the basic idea of what you were trying to do up here, but it looks like this function can't be defined static, and dataTextField if used this function, it would need it to be static. confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Sep-2006 10:05:16   

Why does it have to be static? It's just a property in the entity class.

Frans Bouma | Lead developer LLBLGen Pro