CodeSmith Community
Your Code. Your Way. Faster!

Multiple fields for DataTextField on DropDown lists

Latest post 07-02-2008 12:05 AM by Polar. 9 replies.
  • 11-28-2007 6:51 AM

    Multiple fields for DataTextField on DropDown lists

     I'm sure this is very simple, but I can't seem to figure it out... is there any way of showing the concatenation of more than one field in a dropdown as the DataTextField? For example, I want a select box which lists currently stored documents in my database, but want to show it in the format:

    Title (year)

    at the very least (possibly more fields and even different ones if some are null for example).

    The only way I can think of doing this is to either alter the SP or create a custom one which returns the fields concatenated into a single field, then choosing this field as the DataTextField value... is there a way of doing this in the code rather than the SP?

    Thanks. 

    • Post Points: 35
  • 11-28-2007 8:12 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: Multiple fields for DataTextField on DropDown lists

    Try creating a new property in your entity which has a get accessor that does teh concatentaion for you i.e

     

    public string TitleAndYear
    {
        get { return string.Format( "{0} ({1})", this.Title, this.Year); }
    }

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 11-29-2007 3:17 PM In reply to

    • Polar
    • Top 75 Contributor
    • Joined on 09-04-2007
    • Posts 54
    • Points 1,040

    Re: Multiple fields for DataTextField on DropDown lists

    I've added a new properly set [BindableAttribute(true)] but I still can't access this properly in code.  Whats weird is that another one I made for a different entity works just fine.

    wow my bad. I was looking for the property in <Entity>Columns class lol 

    • Post Points: 35
  • 11-30-2007 5:02 AM In reply to

    Re: Multiple fields for DataTextField on DropDown lists

    Thanks for that Swin, hadn't really thought about putting this type of thing there!

     

    Works a treat. Wink

     

    • Post Points: 35
  • 01-16-2008 2:56 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 735
    • Points 17,045

    Re: Multiple fields for DataTextField on DropDown lists

     The support for that has just been added (rev. 696)

    Bellow is an example: 

    <data:EntityDropDownList runat="server" ID="dataFunctionCodeId" DataSourceID="FunctionCodeIdFunctionCodeDataSource"
                DataTextField="FunctionCode,Desc" DataValueField="FunctionCodeId" DataTextFieldFormatString="{0} - {1}"
                SelectedValue='<%# Bind("FunctionCodeId") %>' AppendNullItem="true" Required="true" NullItemText="< Please Choose ...>" ErrorText="Required" />
            <data:FunctionCodeDataSource ID="FunctionCodeIdFunctionCodeDataSource" runat="server" SelectMethod="GetAll"  />

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 01-17-2008 6:42 PM In reply to

    • dvd
    • Top 100 Contributor
    • Joined on 01-10-2007
    • Posts 48
    • Points 920

    Re: Multiple fields for DataTextField on DropDown lists

    Mike, it looks like changes made to EntityDropDownList in rev. 696 break existing controls. Badly. I updated the templates and regenerated my app this morning, as a result EVERY EntityEntityDropDownList in the application now shows a null item description ("Please select...") instead of correct selected value. Even worse: if the underlying data source contains no items, the exception is thrown:

    capacity was less than the current size.
    Parameter name: value

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: capacity was less than the current size.
    Parameter name: value

    Source Error:

    Line 326:                if (rdsCollection != null)
    Line 327:                {
    Line 328:                    Items.Capacity = rdsCollection.Count;
    Line 329:                }
    Line 330:                bool valid = ((dataTextField.Length >= 0) && (dataValueField.Length >= 0));


    Source File: ...Web\UI\EntityDropDownList.cs    Line: 328

    Please advise...

    • Post Points: 35
  • 01-17-2008 9:57 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 735
    • Points 17,045

    Re: Multiple fields for DataTextField on DropDown lists

    dvd,

    Thanks for the report, the fix has been committed (rev. 697) 

    Those enhancements needed more testing ... i've have made a rollback to the state without Multi-DataTextField support.

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 01-18-2008 3:25 PM In reply to

    • dvd
    • Top 100 Contributor
    • Joined on 01-10-2007
    • Posts 48
    • Points 920

    Re: Multiple fields for DataTextField on DropDown lists

    Right, I got to the same conclusion: after applying rev. 697 dropdowns still have wrong selected values...

    • Post Points: 35
  • 07-01-2008 5:43 AM In reply to

    • Jagmohan
    • Not Ranked
    • Joined on 03-13-2008
    • Posts 4
    • Points 110

    Re: Multiple fields for DataTextField on DropDown lists

    can u plz tell me

    how can we achive this from code behind at runtime insteed of design time.

     

    Thanks. 

    • Post Points: 35
  • 07-02-2008 12:05 AM In reply to

    • Polar
    • Top 75 Contributor
    • Joined on 09-04-2007
    • Posts 54
    • Points 1,040

    Re: Multiple fields for DataTextField on DropDown lists

     Can you add more info about what you want to do exactly Jagmohan?

    • Post Points: 5
Page 1 of 1 (10 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems