Binding to a Dropdown

Posts   
 
    
Posts: 35
Joined: 10-Sep-2006
# Posted on: 10-Sep-2006 03:18:01   

Ok - I have what I think should be a very simple question but the answer is not jumping out at me... I have a simple entity "Employee" with all the normal employee informatin.. Including FirstName and LastName. I can bind a Lastname to display and the ID for the value no problem.. but how can I change the binding so it will display FirstName and LastName as the display text? Do I have to create an Alias in the entity and populate that with FirstName & " " & LastName? I'm sure there is a simple way to accompish.... Note I'm doing my own databinding and not using the LLBL datasources.

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 10-Sep-2006 18:46:53   

You could either create a "FullName" property on your object and bind to that, or manually bind the control to FirstName + " " + LastName.

Posts: 35
Joined: 10-Sep-2006
# Posted on: 11-Sep-2006 03:40:58   

I really don't want to add a new property to my employee class as this is something that is presentation based. When I try to set the datatextfield = firstName + " " + lastname; I get firstName + " " + lastname is not a member of the collection employee. So thats not quite working. Usually I would have a dataset and create a column and then have that be a computed column of first and last name. Can I do something like this in LLBL? Sorry, but I'm new with this tool - though it is very cool saves soooooooooo much time. Any other suggestions?

I guess I could use the databinding event to add last name to the display but that seems like a lot of extra effort.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Sep-2006 07:57:34   

What Todd (Chester) has suggested is the easiest solution. You will add a custom property to the EMployee class without changing the database.

Other solutions will need more effort, such as: creating a dataTable on the fly and bind the dropdownlist to it. Or manually add items to the dropdownlist.

Please check the following link on google groups: [urldescription="google groups link"] http://groups.google.com.eg/group/microsoft.public.dotnet.framework.aspnet/browse_frm/thread/348c56dd52f2b0f8/ce9c5180ceba5ca0?lnk=st&q=dropdownlist+databind+%22full+name%22&rnum=7&hl=en#ce9c5180ceba5ca0[/url]

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 14:55:07   

Hi,

if you don't want to modify your entity class, but still wishes for the Full Name structure to be served by the datasource object rather than manually at binding time, then you can use a dedicated typedlist with a "Full Name" column built thanks to a LLBLGen expression.

That's pretty much what you describe as your former way to do it (TypedList inherits from DataTable)

Posts: 35
Joined: 10-Sep-2006
# Posted on: 11-Sep-2006 21:06:55   

Sorry to admitt to my ignorance but i have just down loaded the demo and in the early phases of going through everything. Can someone direct me on how to create the custom property and assign an expression to it? I don't see it in the help (atleast where it is obvious to me).

Been playing around with the filter and sorting predicate and looking at the sql it creates...very very impressive.. nice work! If I only would of had this a few projects ago...

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 12-Sep-2006 04:17:46   

Check out Generated code - Adding your own code to the generated classes .NET 2.0: Partial classes. You can use a partial class to define a property FullName that returns the concatenation of the FirstName and LastName properties of your entity.