This is a migrated thread and some comments may be shown as answers.

OpenaccessDatasource Query: Combining two fields and populate combo box

3 Answers 112 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerrit du Preez
Top achievements
Rank 1
Gerrit du Preez asked on 22 Oct 2009, 04:48 PM
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

3 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 23 Oct 2009, 02:30 PM
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
0
Gerrit du Preez
Top achievements
Rank 1
answered on 24 Oct 2009, 10:55 AM
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
0
IT-Als
Top achievements
Rank 1
answered on 25 Oct 2009, 11:02 PM
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
Tags
Getting Started
Asked by
Gerrit du Preez
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Gerrit du Preez
Top achievements
Rank 1
Share this question
or