ASP.NET 2.0/C#: Setting default selected item of a dynamically generated dropdownlist?
Posted on 2006-07-20
I am working on web app in asp.net 2.0 and I have stumbled across a problem.
I have a page with a dropdownlist on it, which has an object data source based on the content of a MySql table.
Now, on this page, the user can select, say, an invoice from a dropdownlist.
When the user selects a dropdownlist and presses the "select" button, the 2nd dropdownlist which is also generated from a table, is filled with customers.
Basically, a user selects an invoice that he wants to edit, and then the rest of the page appears with textboxes and dropdownlists that contain the data of the invoice.
I've gotten as far as being able to fillthe textboxes with the invoice data by using:
DataSet ds = ModuleOrders.GetOrder(Order_ID);
lblBeginDatDA.Text = ds.Tables.Rows["Begindatum"].ToString();
ModuleOrder.GetOrder(Order_ID); is a function which gets the invoice data from the database based on the Order_ID which is tied to the first dropdownlist.
This module also returns the customer associated with the selected invoice.
Is it possible to default the 2nd dropdownlist's initially selected index to the customer field in the dataset? I am thinking of something like this:
DropDownListCustomers.InitiallySelectedValue = ds.Tables.Rows["Customer"].ToString();
Does anyone know the correct function and syntax to set the initially selected value of a dropdownlist?