We still have to add the code so that when a user selects an
item in the drop down list the system will retrieve the record and display the
information on the web page. This will be done in the SelectedIndexChanged
event.
1.
Switch back to Design view and double click on the Users drop down
list. This should create the SelectedIndexChanged event handler.
2.
Add the following code.
if (ddlUsers.SelectedValue == "")
{
txtFirstName.Text = "";
txtLastName.Text = "";
lblInserted.Text = "";
lblUpdated.Text = "";
}
else
{
//Get the user from the DB
using (OrderDBContainer db = new OrderDBContainer())
{
int userAccountId = Convert.ToInt32(ddlUsers.SelectedValue);
var userAccounts = from u in db.UserAccounts_SelectById(userAccountId)
select u;
txtFirstName.Text = "";
txtLastName.Text = "";
lblInserted.Text = "";
lblUpdated.Text = "";
foreach (UserAccounts_Select_Result userAccount in userAccounts)
{
txtFirstName.Text = userAccount.FirstName;
txtLastName.Text = userAccount.LastName;
lblInserted.Text = userAccount.AuditFields_InsertDate.ToString();
lblUpdated.Text = userAccount.AuditFields_UpdateDate.ToString();
}
}
}
This code calls the UserAccounts_SelectById method which in
turn executes the stored procedure. The textboxes and labels are set to the
properties of the object that was returned.
If you run the project now you should be able to pull up the
records that were added previously and then update them.