Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDowList Binding
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00671640
Message ID:
00671721
Views:
14
You set the DataSource property of the DDL to the data source of the list (DataView,DataTable). Then you set the DataTextField to the field of the data source that provides the text content of the list items. Finally you set the DataValueField to the field of the data source that provides the value of each list item that you want to save in another DataTable or DataView.

To select an item, you would use the following syntax.
myDropDownList.Items.FindByValue(myKey.Text).Selected = True
As far as using a DataGrid, you can have a DDL inside the grid. Here is an article that explains how to do this:

http://msdn.microsoft.com/msdnmag/issues/01/06/cutting/cutting0106.asp

To bind the DDL you would do something like:
<asp:MyDropDownList
    id=DDList1
    rowid='< % ERROR: # DataBinder.Eval(Container.DataItem, "IDFromGridDataSource")
 % >'
    OnItemDataBound="Item_Bound"
   runat="server">
</mydropdownlist>
Use the OnItemDataBound method to provide a custom handler for the ItemDataBound event. The ItemDataBound event is raised after an item is data bound to the DataGrid control. In the method, set the selected item using the sample code as shown above where you set the Selected property of the Item to True.


>I'm trying to build a DropDownList class for use in an ASP.net project. How do you get the DDL bound to a field while using a lookup table to populate it? IOW, how do I get it to come up on screen showing the proper item selected?
>
>Part 2: Is it possible to achieve this in a DataGrid?
>
>TIA,
>
>--Ken
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform