[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dropdown list data Binding based on a selection from another list.

Posted on 2005-04-14
3
Medium Priority
?
318 Views
Last Modified: 2006-11-18
Hello.


i have a Webform with two drop down lists. The first list gets it's data from my SQL database, from a table named Schools.

Now,i will use the second list it to populate the departments which belong to the selected school from the 1st List.

How can i make my second list query the database and return all the Departments which belong to the selected School. I want to do this without reloading the page.

Is this possible.

Thank you.
0
Comment
Question by:Globemaster
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
snavebelac earned 500 total points
ID: 13787004
In order to populate the second list box from the database the page has to be reloaded as the client has to make an additional query to the server and then show the resultant page.

Dynamic boxes of this type can be coded client side using JavaScript but all the departmenst for each school would have to be retrieved and stored in Javascript arrays prior to the page being constructed by the server.  JavaScript can be constructed Dynamicaly just like HTML can.

So, short answer is no it cannot be done unless you use some client side Javascript.

HTH

C
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13787375
Actually, it could be done without reloading the page, but this is a little used method.

If you make a second ASP page, that only returns the department's list given a URL parameter, (e.g. no HTML tags other than the list box), you can use the XMLHTTP component to retrieve the second list.  I'll call that page getDeptSelect.asp, it would be called, like:  getDeptSelect.asp?school=nameOfSchool

In your main page the schools list needs an onchange event and associated function....

<select name="school" onchange="getDepts(this)">
  ....
</select>

Your departments select needs to be inside some entity which has a unique ID, say a divide...

<div id="deptSel">
  <select name="dept"><option>Select School</option></select>
</div>

function getDepts() will be JavaScript...

<script language="javascript" type="text/javascript">
<!--
function getDepts(oSel) {
    var school = oSel[oSel.selectedIndex].value;
    var oHTTP = new XMLHttpRequest();
    oHTTP.open('GET', 'getDeptSelect.asp?school='+school, false);
    oHTTP.send(null);
    oHTTP = xmlHttp.responseText;

    // oHTTP now has the results from getDeptSelect.asp which should be
    //  <select name="department"><option>....</option></select>

    // put the select into the proper page location
    document.getElementById('deptSel').innerHTML = oHTTP;
}
//-->
</script>

Reference on the XMLHTTP object can be found here: http://www.w3schools.com/dom/dom_http.asp and there are examples on 4guysfromrolla.com and other ASP locations.

Regards,
Rod

0
 
LVL 6

Expert Comment

by:snavebelac
ID: 13789056
That is a neat solution but still requires the use of client side code and will still suiffer the delay of  a reload as the script loads the page from the server.

I like the implementation though.

C
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question