OpenaccessDatasource Query: Combining two fields and populate combo box

4 posts, 0 answers
  1. Gerrit du Preez
    Gerrit du Preez avatar
    35 posts
    Member since:
    Aug 2012

    Posted 22 Oct 2009 Link to this post

    Hi there

    I am using an OpenAccessDatasource and want to select two fields (Firsname and Surname) and combine them into one to populate a cobo box.

    In other words: In my database I have a field for Firstname and one for Surname.  I want to populate a combobox with values where these two are joined together  to display the name and surname in the drop down list. 

    How can this be achieved by using the OpenAccessDatasource?  I want to use this approach as well in the RadScheduler and would like to run the query in my aspx page and not from the code behind.

    Thank you

    Gerrit
  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 23 Oct 2009 Link to this post

    Hi Gerrit,

    One way it can be solved is to introduce a transient read only property on your class (for example the class Person) and have this property getter combine the firstname and surname field to return the full name, like this:

    public class Person
    {
      // Persistent fields
      string firstname;
      string surname;

      // Properties for firstname and lastname fields not shown for clarity

      // The readonly getter to combine the name
      string Fullname
     {
       get
       {
          return firstname + " " + lastname
       }
     }
    }

    and then you bind the display text of the combo to that readonly property.

    Regards

    Henrik
  3. DevCraft banner
  4. Gerrit du Preez
    Gerrit du Preez avatar
    35 posts
    Member since:
    Aug 2012

    Posted 24 Oct 2009 Link to this post

    Hi Henrik

    Thanks for your reply.

    I tried it and added it as follows to my User class

           public string Fullname  
            {  
                get { return firstname + ' ' + lastname; }  
     
            } 

    I now get this error:

    Identifier 'Fullname' is not a parameter or variable or field of 'OpenAccessData.User'. If 'Fullname' is a property please add the FieldAlias attribute to it.

    I tried adding a FieldAlias attribute, but then it returns only the value of the field specified in the FieldAlias and not a concatenated value of the two fields.

    Any advise?

    Thanks

    Gerrit
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 25 Oct 2009 Link to this post

    Hi Gerrit,

    I really can't think of any issues here.. Maybe you can post some more code: the query (in the aspx page I suppose) the collects the information, the binding and the class definition..and I'll take a look..

    Regards

    Henrik
Back to Top