Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : ASP : ASP 3.0 : How to equate a database record set value to a drop down list in asp Signup · Login
Author Thread
How to equate a database record set value to a drop down list in asp
Posted in tutorial: An ASP Tutorial to create your own Database driven Search Engine
·  naresh_Kumar
User
Joined: 1 Dec 2004
Total Posts: 1

How to equate a database record set value to a drop down list in asp

Posted: 1 Dec 2004
Sir,
here i am creating a shopping cart taking the value from the msaccess database like proid, name, descri.etc i am able to equate record set value ie rs(0) to a check box and i would like to ask you how to equate the same rs(0) to the drop down list box.
Please help me soon sir..
thank you



·  coolgal
User
Joined: 30 Jan 2005
Total Posts: 1
equating a database record
Posted: 30 Jan 2005
I) If u want to populate ur dropdown with reordset then use:-
this is an examle where i populate poduct names into dropdown and use product id to any particular option's value.
<select name="product">
<option value="">-----------------</option>
<%Do while not rs.eof %>
<option value="<%=rs("ProductID")%>"><%=rs("ProductName")%></option>
<%
rs.movenext
Loop
%>
</select>

II) if u want to show any particular option selected onload then two options:
First is using vbscript only:-
use if statement
<select name="product">
<option value="">-----------------</option>
<%Do while not rs.eof %>
<% if strprodid = rs("ProductId") then %>
<option value="<%=rs("ProductID")%>" selected>
<%=rs("ProductName")%>
</option>
<% else %>
<option value="<%=rs("ProductID")%>">
<%=rs("ProductName")%>
</option>
<%
end if
rs.movenext
Loop
%>
</select>

where strprodid contains product id which u want to select.it could be dynamically sent through querystring.

Secondly it could be done thro' javascript

function onload()
{
var i;
var ind = document.frm.productid.value;
for (i=0;i<document.frm.product.length;i++)
{
if(document.frm.product.options[i].value == ind)
{
document.frm.product.options[i].selected = true;
}
}
}
this function could be called at the loading of page in body tag.
here productid is hidden text box containing dynamic value

i hope this information willl be useful

a computer graduate ,involved in asp too much
Want to leave a comment? Login or Register for free!

Users Who Have Visited This Thread In Last 24 Hours
2 Visitors

Login to post a comment or start a new thread
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.