The first task
we'll do is to load the drop down list in the page load event with the list of
records in the UserAccounts table. We'll also add an extra entry in the list
to allow the user to select the option of creating a new user.
Double click on the web form in Design view to create the Page_Load
event in the code behind.
Add the following using statement.
Add the following code to the Page_Load event.
protected void Page_Load(object sender, EventArgs e)
The LoadUserDropDownList is a custom method that you must create.
private void LoadUserDropDownList()
ddlUsers.DataSource = UserAccountEO.SelectAll();
ddlUsers.DataTextField = "FullName";
ddlUsers.DataValueField = "Id";
ddlUsers.Items.Insert(0, new ListItem("Create New User", ""));
The drop down list's DataSource source property is set to
the List of UserAccountEO objects that are returned from the
UserAccountEO.SelectAll method. The DataTextField is then set to "FullName".
The DataValueField is then set to "Id". The next line binds the data
to the drop down list. The last line adds a new item to the list in the first
position. The text of the item is "Create New User" and this will be
used to determine if the user is adding or updating an existing user.
Set the OrderSystemUI project as the startup project and set
this page as the startup page and run the solution. There are no records in
the table yet so all you'll see is the "Create New User" entry in the
drop down list.