Listbox, AutoPostBack and this.Page_Load

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 4 listbox which relate to 4 tables

Here is the DB schema
Departmen
did in
departmentname nvarcha

Staf
sid in
staffname nvarcha
did int //FK of Departmen

Compan
cid in
companyname nvarcha

Contact Perso
pid in
contactname nvarcha
cid int //FK of Departmen

So, all staff are under their respective departments and all contact people are under their respective companies

For instance
Dept listbox Staff listbo
Account dept To
Mar
Eddi
Sales dept Jo
Edwar
Winni

Company listbox ContactPerson listbo
ABC co. Jenni
Edit
Georg
XYZ co. Alla
Josep
Be

I set Dept and Company listbox have autopostback.
When I select account dept, Tom, Mary and Eddie will appear in Staff listbox.
When I select sales dept, Joe, Edward and Winnie will appear in Staff listbox
When I select ABC co, Jennie, Edith and George will appear in ContactPerson listbox.
When I select XYZ co, Allan, Joseph and Ben will appear in ContactPerson listbox

Here is the C# code:
private void InitializeComponent(
{
this.listDept.SelectedIndexChanged += new System.EventHandler(this.listDept_SelectedIndexChanged)
this.listCompany.SelectedIndexChanged += new System.EventHandler(this.listCompany_SelectedIndexChanged)
this.Load += new System.EventHandler(this.Page_Load)


Page_Loa
this.ListDeptDataBind()
this.ListCompanyDataBind()

The page refreshes each time when I select item in dept or company listbox. If I select account dept, Tom, Mary and Eddie will appear in Staff listbox.

However, Tom, Mary and Eddie will disappear in Staff listbox when I select ABC co.

It was because the this.Load += new System.EventHandler(this.Page_Load) each time when I select

So, how can I fix this problem? I need to show both data in staff and contactperson listbox at the same time

Thanks for help
 
I added OnSelectedIndexChanged="listDeptGroup_SelectedIndexChanged" to listbox and removed the this.listDeptGroup.SelectedIndexChanged += new System.EventHandler(this.listDeptGroup_SelectedIndexChanged)

But, same result as before. 2nd listbox's value was removed when I clicked listitem in 1st listbox.

What do you mean " Value property of the ListBox " ? How can I fix this problem with it? Could you show me an example of code?
 
Back
Top