0

I have 4 listboxes (lstStates, lstCounties, lstCities, and lstZipcodes). Here are a few constraints:

  • None of the listboxes are disabled.

  • Any listbox can be selected at anytime, meaning there is no specific order the user has to choose.

  • Filtering is forward and backwards. By this, I mean if a user selects a state from lstStates, it will filter lstCounties, lstCities, and lstZipcodes. If a user selects a zipcode from lstZipcodes, it will filter lstCities, lstCounties, and lstStates.

  • The listboxes allow multiple selections.

Each listbox is bound to a datatable to get its initial data. The datatable is retrieved from a sqlserver stored procedure. Each listbox has its own stored procedure, for example, lstStates has one called GetStates which returns one column (State) and the ListBoxes DataValueField and DataTextField are both set to State. Similar to lstStates, lstCities is bound to a datatable which gets one column from a GetCities stored proc which is city.

Another thing I want to point out is that I am connecting an ObjectDataSource to get the datatable.

4

3 回答 3

2

Already been asked: What is the most efficient way to filter listboxes based on selections of another in c#?

[edit] OK, what you need to do is add an event to each [myListbox]_SelectedIndexChanged event. When the selection is changed you'll need to refresh all the other listboxes based on those selections. I assume that this will need to be handled by the database, since linking States to ZipCodes any other way would be ugly. So presumably your data for States<-->Zips<-->Counties relationships is in your db somewhere.

So you'll need to have procs in your db (or LINQ middle layer) that get States by Zips and so on. On each selection changed event, send the new selection back to the db sproc and then rebind the listbox based on the return data. You should be able to make one sproc for each one that returns all states if no zip is passed in and so on. [/edit]

于 2009-01-06T20:27:26.750 回答
0

To clarify, on your initial load of the page, you are loading ALL zipcodes, ALL cities, ALL states and ALL countries?

This seems a bit cumbersome to me. This is the type of requirement I would question. (Granted I don't know that you didn't already question it or that some good answer came from it).

于 2009-01-06T20:47:54.603 回答
0

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bab", "CacheItems();", true);

var ddlText, ddlValue, ddl, lblMesg; function CacheItems() { ddlText = new Array(); ddlValue = new Array(); ddl = document.getElementById(""); for (var i = 0; i
于 2013-10-08T10:53:41.663 回答