Basically I have a listview that is bounded on page load to the Customers table in the db.
What I am trying to achieve is when I select a specific customer on the listview, it should fetch data from the database for that specific customer and populate the textboxes so I can modify details.
I am programming using 3 tier procedures.
Any help would be appreciated. I basically want something like this int CustomerID = lstCustomers.selected????.value
So that I can pass the customer ID into another method and retrieve details.
my code is below:
private void GetCustomerList()
{
List customersList = new List();
try
{
customersList = CustomersDB.GetCustomers();
if (customersList.Count > 0)
{
Customer customer;
for (int i=0; i < customersList.Count; i++)
{
customer = customersList[i];
lstCustomers.Items.Add(customer.CustomerID.ToString());
lstCustomers.Items[i].SubItems.Add(customer.FirstName.ToString());
lstCustomers.Items[i].SubItems.Add(customer.LastName.ToString());
lstCustomers.Items[i].SubItems.Add(customer.DateJoined.ToShortDateString());
lstCustomers.Items[i].SubItems.Add(customer.Telephone.ToString());
lstCustomers.Items[i].SubItems.Add(customer.Email.ToString());
}
}
else
{
MessageBox.Show("No customers exist in the database");
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
this.Close();
}
}
private void lstCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
}
Thanks for any help
Maz HussainPosted Feb 11, 2012, 7:03 PM
Thank you soooo much, there were so many different methods I was trying.
.NET is so huge at the moment for me, I have much to learn but aspire to be a good developer one day.
Kind regards
VulpesPosted Feb 11, 2012, 6:28 PM