Databinding a dropdown list with namevalue list

Databinding a dropdown list with namevalue list

Old forum URL: forums.lhotka.net/forums/t/2909.aspx


dev posted on Sunday, May 20, 2007

I am binding a dropdown list to a namevalue list. The control populates with the values from the lookup table but the event does not fire on page postpack and I can therefore not read the selected value. I can also not get the value in the database to be the visible item when the page is displayed.

Expert one-on-one Visual Basic .NET Business Objects does not seem to describe the binding process or I have missed it. Perhaps it's so trivial, it's not necessary.

Can someone please help me out here?

Plowking replied on Monday, May 21, 2007

What kind of form are you creating, are you presenting an edit screen for a CSLA business object?

Perhaps you are binding the dropdownlist to a business object's property, for example a CountryList object where you select a country from the dropdown to populate an address objects country property, for example.

Here, you view the business object in a details view, where the datasource is defined as your business object. the dropdown list is then a field in your details view.

The dropdownlist isnt "bound" to your namevaluelist, but uses it as its datasource. The dropdownlist's SelectedValue property is then bound to your address objects country property.

To set a default value for your dropdown list, what you must do in fact is set the default value for your business objects property when it is instanciated for the first time, so your address objects country property should default to "Denmark" for example. You do this either in the dataportal create method or in the constructor of your business object (although doing it in the constructor isnt really the CSLA way)

Have a look in the project tracker sample application for examples of how this is done.

Otherwise your question isnt really CSLA specific, and you should be able to find examples of using a dropdownlist with a google :)

Ian

dev replied on Thursday, May 24, 2007

Thank you so much for your input. You are absolutely right. I am using a table as a datasource only.

The table in fact is a table containing the languages of the world. The user can select a home language. The screen is an ASP.NET screen on which you can create yourself as a user on the system. You are required to supply personal information including your home language. The home language is selected from the drowpdown list. When the user returns to edit their particulars the user's selected home language should be displayed in the dropdown list. The language exists as a property on e.g. a person object. myperson_object.homelanguage.

So, what you are saying is that I should use the namevalue list as a datasource and databind myperson_object.homelanguage to the dropdownlist...

I will give this a shot and let you know of the outcome. If you have any code that can demo this, it would be appreciated!

Thanks again for your help.

Copyright (c) Marimer LLC