Databinding a ASP:DropDownList

Databinding a ASP:DropDownList

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


JonM posted on Thursday, July 17, 2008

I am just starting to get into CSLA.net with ASP.net.  I can't seem to figure out how to bind one of my business object properties to a DropDownList.   I've bound a readonlylist of business objects to the dropdownlist's datasource and have set the DataTextField and DataValueField.  The list of readonly items populates just fine.  How do I bind the selected item of the DropDownList to my business object?  Does it work anything like WinForms?

RockfordLhotka replied on Thursday, July 17, 2008

Usually the business object itself is bound to a GridView, DetailsView or FormView control. All other controls (if any) are inside one of these container controls.

So if you want to use an explicit DropDownList, you'd put it in a FormView. Or you can just use a GridView or DetailsView and set the column type to be a dropdown.

JonM replied on Thursday, July 17, 2008

Okay.  I got it.  I just did a Bind on the SelectedItem of the DropDownList.  The control was in a FormView.   Any ideas on how to add a null item (or rather a Guid.Empty) item?

Copyright (c) Marimer LLC