Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "Dynamic dropdown list with multiple records" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). Visit the ASP Development forum for help with ASP/VBScript and ASP/JScript applications.


Closed Thread
 
LinkBack Thread Tools Display Modes
  #1  
Old March 27th, 2008, 02:26 PM
Rebelle's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 295
Thanks: 54
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default Dynamic dropdown list with multiple records

Hi All,

I have a search screen with allows many different searches and results. The results can be one or many records. After results are displayed I have an Edit button to edit the record(s). Well, the two fields Region / District go hand in hand. The code below works but what happens is...let's say I search for Region "Africa", I may get 10 records, well, let's say I want to change two of the records to a different Region (like "Canada"), I do see "Canada" in the list but when I select it, it doesn't update the District list....I will still see the districts for Africa, so I have to save my Region "Canada", then go search for "Canada" records and then I'll see the "Canada" districts and I can pick one.

Is there a way to submit when a new Region is selected when in the edit mode on multiple records so it could update the District list?

Hope this makes sense, let me know if you have any more questions and Thanks for any direction and help!

Code:
<TD>
          <SELECT CLASS="clrBg" name="RegionName<%response.write(i)%>">
		'onChange="frmSearch.action='EditAssetList4.asp';frmSearch.submit();"
<%
strSQL = "Select Distinct RegionName,RegionID from vwReg_Dist"
set rs2 = conn.execute(strSQL)
strRegionID = rs("RegionID")

response.write Space(16) & "<option value=""0"">Select Region</option>"

Do While Not rs2.EOF
	response.write Space(16) & "<option value=""" & rs2("RegionID") & """"
	If CStr(rs2("RegionID")) = CStr(strRegionID) Then
		response.write " selected"
	End If
	response.write ">" & rs2("RegionName") & "</option>" & vbCrLf
rs2.MoveNext
Loop
%>
<% rs2.Close
   set rs2 = Nothing
%>	
          </SELECT> 
	  </TD>
          
<TD>
	<SELECT CLASS="clrBg" name="District<%response.write(i)%>">
<%
strSQL2 = "Select Distinct Concatenate, DistrictID from vwReg_Dist where RegionID='" & strRegionID & "' Order by Concatenate"
	set rs3 = conn.execute(strSQL2)
	strRegionID = rs("RegionID")
	strDistrictID = rs("DistrictID")
	
	response.write Space(16) & "<option value=""0"">Select District</option>"

	Do while not rs3.eof
		response.write Space(16) & "<option value=""" & rs3("DistrictID") & """"
		If CStr(rs3("DistrictID")) = CStr(strDistrictID) then
			response.write " selected"
		End If
		response.write ">" & rs3("Concatenate") & "</option>" & vbCrLf
	rs3.MoveNext
	Loop
%>
<%	
rs3.Close
set rs3 = Nothing
%>

	</SELECT>
	</TD>
Sponsored Links
  #2  
Old March 27th, 2008, 04:07 PM
BLaaaaaaaaaarche's Avatar
Moderator
 
Join Date: Mar 2008
Posts: 55
Thanks: 10
Thanked 7 Times in 5 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
HTML & CSS Classic ASP 
Total Awards: 2

Default

You have been working on this for a while now, haven't you? I think you logic is wrong. Based on the code I see, I do not see where you define the recordset "rs". Also, why do you keep referencing the "rs" recordset? Why not store that value in a variable and close the connection? That would be much more efficient.

Anways, I am not sure what you are trying to accomplish here? To clean up your code, I would suggest that you use subs to create your selects. For instance, like so:

Code:
Sub DistrictSelect(intID, intRegionID, intDistrictID)
	strSQL = "SELECT DISTINCT Concatenate, DistrictID FROM vmReg_Dist WHERE RegionID = '" & strRegionID & "' ORDER BY Concatenate"
	Set objRS = conn.Execute(strSQL)

	response.write "<select name=""District" & intID & """ class=""clrBg"">" & vbCrLf
	response.write "<option value="""">Select District</option>" & vbcrLf
	Do While Not objRS.EOF
		response.write "<option value=""" & objRS("DistrictID") & """"
		If CStr(objRS("DistrictID")) = CStr(strDistrictID) Then
			response.write " selected"
		End If
		response.write ">" & objRS("Concatenate") & "</option>" & vbCrLf
	objRS.MoveNext
	Loop
	response.write "</select>" & vbCrLf

	objRS.Close
	Set objRS = Nothing
End Sub
Then, you can easily pass along your values to the sub:

Code:
intRegionID = rs("RegionID")
intDistrictID = rs("DistrictID")
intID = 10
And to call the sub from within your table, use this:

Code:
<tr>
  <td><% Call DistrictSelect(intID, intRegionID, intDistrictID) %></td>
</tr>
Once you do this, you may be able to cleary see where you are going wrong.
  #3  
Old March 27th, 2008, 04:29 PM
Rebelle's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 295
Thanks: 54
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

Hi BLaaaaaaaaaarche,

Yes, Ok, let me go and change it back. I had your suggestion before and it did work and make the code cleaner but still couldn't figure how to do an OnChange to update the district list only for the one record with multiple records on the screen.

My screen looks similar to this:

Region List --District List--Category List--Size List--Desc--more fields

Africa Angola Hammer 8" 8" Hammer
Africa Congo Hammer 6" 6" Hammer

So if I want to change the second record Region to Canada, I can do so but the District list won't show Canada district, it still shows Africas districts.

I'll come back once I change the code back and see how I can implement the OnChange or something similar to do this.

Thank you
  #4  
Old March 27th, 2008, 05:55 PM
BLaaaaaaaaaarche's Avatar
Moderator
 
Join Date: Mar 2008
Posts: 55
Thanks: 10
Thanked 7 Times in 5 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
HTML & CSS Classic ASP 
Total Awards: 2

Default

It might help if you provide us with a sample of your DB and your full code as I have no idea what you are trying to accomplish.
  #5  
Old April 30th, 2008, 05:33 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 460
Thanks: 31
Thanked 43 Times in 43 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

Due to inactivity of 14 days, this thread is deemed abandoned and is now closed. If this thread was marked as "Solved", the orginal poster may mark it as "Unsolved" via the Thread Tools menu, thus re-opening the thread. If this thread was not marked as "Solved", the original poster may re-open the thread via the Thread Tools menu.

Regards,

richyrich
DeveloperBarn Forums Moderator
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -4. The time now is 09:14 AM.



Content Relevant URLs by vBSEO 3.2.0