p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_forms thread: Dynamic List Box


Message #1 by "sahil Rahul421@u... on 31 Dec 2000 10:20:44 -0000
Dear All,







I have two list box in my page.  The 1st list box data is retreived 

through a sql server database.  What I want is upon selecting a category 

in list box 1(one) the 2nd list box has to retrieve the data from sql 

server but different database.







I tried a lot and worked on it.  But i haven't got the solution.  







I request all of you to help me in this regard.







Thanks & Best Regards for New Year,



Sahil





---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.

---

You are currently subscribed to asp_forms as: $subst('Recip.EmailAddr')

To unsubscribe send a blank email to leave-asp_forms-$subst('Recip.MemberIDChar')@p2p.wrox.com

Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 02 Jan 2001 09:18:47 +0100
This shouldn't be too difficult.



I will outline a little plan, in which you have to fill in the details 

yourself. If you need more help, let me know.



' Check for post back.

If Request.Form("lstOne") = "" then ' lstOne is the first select / 

drop-down box

         ' If empty, page is requested for the first time.

         Dim sSQL

         sSQL = "SELECT id, description FROM table1 ORDER BY description

         ' Declare and set your recordsetobjects and connections here.

         Recordset.open sSQL, ConnectionToDatabase1, adOpenForwardOnly, 

adLockReadOnly

         sList = "<SELECT ID=""lstOne" NAME=""lstOne"">"

         if not Recordset.EOF then

                 ' Loop through the recordset and add an item for each 

record in the database

                 ' Use the id as value, and show the description in the list

                 do while not Recordset.EOF

                         sSQL = sSQL & "<OPTION VALUE=""" & 

Recordset.Fields.Item(0) & """>" _

                                 & Recordset.Fields.Item(1) & "</option>"

                         Recordset.MoveNext

                 loop

         end if

         Recordset.Close

         sList = sList & "</select>"

         Response.Write(sList)

         ' Make sure that you have already written the <FORM> tags. Also 

make sure you have a submit button.

         ' You'll need them to have the user do the postback to the page.

else

         ' Page is posted back. This means the user clicked the submitbutton,

         ' so retrieve the selected value

         Dim iID

         iID = Request.Form("lstOne")

         ' Use iID for the lookup.

         sSQL = "SELECT id, description FROM table2 WHERE id = " & iID & " 

ORDER BY description

         Recordset.open sSQL, ConnectionToDatabase2, adOpenForwardOnly, 

adLockReadOnly

         ' etc etc. From here the code will pretty much the same as the 

first example.

end if





This example uses one ASP page for both the lookups. If you set the action 

of the form to a second page, you could do the lookup there as well.





HtH



Imar





At 10:20 AM 12/31/2000 +0000, you wrote:

>Dear All,

>

>

>

>I have two list box in my page.  The 1st list box data is retreived

>through a sql server database.  What I want is upon selecting a category

>in list box 1(one) the 2nd list box has to retrieve the data from sql

>server but different database.

>

>

>

>I tried a lot and worked on it.  But i haven't got the solution.

>

>

>

>I request all of you to help me in this regard.

>

>

>

>Thanks & Best Regards for New Year,

>

>Sahil

>

>









---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.

---

You are currently subscribed to asp_forms as: $subst('Recip.EmailAddr')

To unsubscribe send a blank email to leave-asp_forms-$subst('Recip.MemberIDChar')@p2p.wrox.com

Message #3 by "sahil Rahul421@u... on 2 Jan 2001 19:42:22 -0000
Dear Imar,







Many thanks for your help.  But I tried a lot and I could'nt get what i needed.  Please have a look once again to my
problem/question.







LIST BOX 1:-					



1. Type_MainCategory (which is in x1 database of SQL Server 7.0)











I have fetched the Type_MainCategory_Details from 



x1 database to list box 1.







Which has 50 records(categories)











Now what I want is Suppose I select a one Category from list box 1. 



I should get all the details from Type_SubCategory(which is in x2 database of Sql Server 7.0) into the LIST BOX 2.







Please, let me know the solution into the context of the above



i.e getting data dynamically into listbox 2.







Best Regards and New Year Wishes,



Sahil



						

















































On Tue, 02 Jan 2001 09:18:47 +0100 Imar Spaanjaars <Imar@S...> wrote:



>This shouldn't be too difficult.



>



>I will outline a little plan, in which you have to fill in the details 



>yourself. If you need more help, let me know.



>



>' Check for post back.



>If Request.Form("lstOne") = "" then ' lstOne is the first select / 



>drop-down box



>         ' If empty, page is requested for the first time.



>         Dim sSQL



>         sSQL = "SELECT id, description FROM table1 ORDER BY description



>         ' Declare and set your recordsetobjects and connections here.



>         Recordset.open sSQL, ConnectionToDatabase1, adOpenForwardOnly, 



>adLockReadOnly



>         sList = "<SELECT ID=""lstOne" NAME=""lstOne"">"



>         if not Recordset.EOF then



>                 ' Loop through the recordset and add an item for each 



>record in the database



>                 ' Use the id as value, and show the description in the list



>                 do while not Recordset.EOF



>                         sSQL = sSQL & "<OPTION VALUE=""" & 



>Recordset.Fields.Item(0) & """>" _



>                                 & Recordset.Fields.Item(1) & "</option>"



>                         Recordset.MoveNext



>                 loop



>         end if



>         Recordset.Close



>         sList = sList & "</select>"



>         Response.Write(sList)



>         ' Make sure that you have already written the <FORM> tags. Also 



>make sure you have a submit button.



>         ' You'll need them to have the user do the postback to the page.



>else



>         ' Page is posted back. This means the user clicked the submitbutton,



>         ' so retrieve the selected value



>         Dim iID



>         iID = Request.Form("lstOne")



>         ' Use iID for the lookup.



>         sSQL = "SELECT id, description FROM table2 WHERE id = " & iID & " 



>ORDER BY description



>         Recordset.open sSQL, ConnectionToDatabase2, adOpenForwardOnly, 



>adLockReadOnly



>         ' etc etc. From here the code will pretty much the same as the 



>first example.



>end if



>



>



>This example uses one ASP page for both the lookups. If you set the action 



>of the form to a second page, you could do the lookup there as well.



>



>



>HtH



>



>Imar



>



>



>At 10:20 AM 12/31/2000 +0000, you wrote:



>>Dear All,



>>



>>



>>



>>I have two list box in my page.  The 1st list box data is retreived



>>through a sql server database.  What I want is upon selecting a category



>>in list box 1(one) the 2nd list box has to retrieve the data from sql



>>server but different database.



>>



>>



>>



>>I tried a lot and worked on it.  But i haven't got the solution.



>>



>>



>>



>>I request all of you to help me in this regard.



>>



>>



>>



>>Thanks & Best Regards for New Year,



>>



>>Sahil



>>



>>





---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.

---

You are currently subscribed to asp_forms as: $subst('Recip.EmailAddr')

To unsubscribe send a blank email to leave-asp_forms-$subst('Recip.MemberIDChar')@p2p.wrox.com

Message #4 by Imar Spaanjaars <Imar@S...> on Wed, 03 Jan 2001 11:13:22 +0100
If you want the page to be submitted after the user selects an item from 

the first list, I still think my approach should work.

Basically what it does is send the ID of an item to the page itself. This 

ID is then used to retrieve "connected" items in an other database.



If you want all this to happen client side, I suggest you read the 

following articles on aspToday.com



http://www.asptoday.com/articles/20000414.htm



HtH



Imar







At 07:42 PM 1/2/2001 +0000, you wrote:

>Dear Imar,

>

>

>

>Many thanks for your help.  But I tried a lot and I could'nt get what i 

>needed.  Please have a look once again to my problem/question.

>

>

>

>LIST BOX 1:-

>

>1. Type_MainCategory (which is in x1 database of SQL Server 7.0)

>

>

>

>

>

>I have fetched the Type_MainCategory_Details from

>

>x1 database to list box 1.

>

>

>

>Which has 50 records(categories)

>

>

>

>

>

>Now what I want is Suppose I select a one Category from list box 1.

>

>I should get all the details from Type_SubCategory(which is in x2 database 

>of Sql Server 7.0) into the LIST BOX 2.

>

>

>

>Please, let me know the solution into the context of the above

>

>i.e getting data dynamically into listbox 2.

>

>

>

>Best Regards and New Year Wishes,

>

>Sahil

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>On Tue, 02 Jan 2001 09:18:47 +0100 Imar Spaanjaars <Imar@S...> 

>wrote:

>

> >This shouldn't be too difficult.

>

> >

>

> >I will outline a little plan, in which you have to fill in the details

>

> >yourself. If you need more help, let me know.

>

> >

>

> >' Check for post back.

>

> >If Request.Form("lstOne") = "" then ' lstOne is the first select /

>

> >drop-down box

>

> >         ' If empty, page is requested for the first time.

>

> >         Dim sSQL

>

> >         sSQL = "SELECT id, description FROM table1 ORDER BY description

>

> >         ' Declare and set your recordsetobjects and connections here.

>

> >         Recordset.open sSQL, ConnectionToDatabase1, adOpenForwardOnly,

>

> >adLockReadOnly

>

> >         sList = "<SELECT ID=""lstOne" NAME=""lstOne"">"

>

> >         if not Recordset.EOF then

>

> >                 ' Loop through the recordset and add an item for each

>

> >record in the database

>

> >                 ' Use the id as value, and show the description in the list

>

> >                 do while not Recordset.EOF

>

> >                         sSQL = sSQL & "<OPTION VALUE=""" &

>

> >Recordset.Fields.Item(0) & """>" _

>

> >                                 & Recordset.Fields.Item(1) & "</option>"

>

> >                         Recordset.MoveNext

>

> >                 loop

>

> >         end if

>

> >         Recordset.Close

>

> >         sList = sList & "</select>"

>

> >         Response.Write(sList)

>

> >         ' Make sure that you have already written the <FORM> tags. Also

>

> >make sure you have a submit button.

>

> >         ' You'll need them to have the user do the postback to the page.

>

> >else

>

> >         ' Page is posted back. This means the user clicked the 

> submitbutton,

>

> >         ' so retrieve the selected value

>

> >         Dim iID

>

> >         iID = Request.Form("lstOne")

>

> >         ' Use iID for the lookup.

>

> >         sSQL = "SELECT id, description FROM table2 WHERE id = " & iID & "

>

> >ORDER BY description

>

> >         Recordset.open sSQL, ConnectionToDatabase2, adOpenForwardOnly,

>

> >adLockReadOnly

>

> >         ' etc etc. From here the code will pretty much the same as the

>

> >first example.

>

> >end if

>

> >

>

> >

>

> >This example uses one ASP page for both the lookups. If you set the action

>

> >of the form to a second page, you could do the lookup there as well.

>

> >

>

> >

>

> >HtH

>

> >

>

> >Imar

>

> >

>

> >

>

> >At 10:20 AM 12/31/2000 +0000, you wrote:

>

> >>Dear All,

>

> >>

>

> >>

>

> >>

>

> >>I have two list box in my page.  The 1st list box data is retreived

>

> >>through a sql server database.  What I want is upon selecting a category

>

> >>in list box 1(one) the 2nd list box has to retrieve the data from sql

>

> >>server but different database.

>

> >>

>

> >>

>

> >>

>

> >>I tried a lot and worked on it.  But i haven't got the solution.

>

> >>

>

> >>

>

> >>

>

> >>I request all of you to help me in this regard.

>

> >>

>

> >>

>

> >>

>

> >>Thanks & Best Regards for New Year,

>

> >>

>

> >>Sahil

>

> >>

>

> >>

>

>

>---









---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.

---

You are currently subscribed to asp_forms as: $subst('Recip.EmailAddr')

To unsubscribe send a blank email to leave-asp_forms-$subst('Recip.MemberIDChar')@p2p.wrox.com


  Return to Index