Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating combo box with many items quickly

Status
Not open for further replies.

nuVBer

Programmer
Jul 6, 2001
63
0
0
US
I am building a combo box (drop down) on a html page and using js to dynamically populate it with a recordset. It has approx 5000 records and takes about 2 minutes to load. The code looks something like this:

While (!rs.EOF)
{
frm1.cboCC.options = new Options(rs("cost_cent") + " - " + rs("costcentnum").value, rs("cost_cent").value;
i++;
rs.movenext;
}

Is there a quicker way to do this?
 
Use getrows instead of pulling each item individually.

Code:
oRS.Source = "SELECT cost_cent, costcentnum FROM WHATEVER";
oRS.Open();

var arr = oRS.GetRows();
oRS.Close;
var arrSize = arr.ubound(2);
var arrCount = 0;

if (arrSize > 0) {
   while (arrCount <= arrSize) {
      var cost_cent = arr.getItem(0, arrCount);
      var costcentnum = arr.getItem(1, arrCount);
      frm1.cboCC.options = new Options(cost_cent + &quot; - &quot; + costcentnum, cost_cent);
      arrCount++;
   }
}

note your connection is closed sooner too so it frees up bandwidth for other users

-kaht
 
Well, yea that works, but it is only slightly faster than what I was using...maybe 1% faster. I suppose I was looking at maybe a different concept. Thanks for the help though.
 
Better still, put all HTML in the SQL....

Response.Write(&quot;<SELECT>&quot;)
dim strSql, rsAny
strSql = &quot;select '<OPTION value=' || costcentnum & &quot;' || ' >' || &quot; & cost_cent & &quot; - &quot; & costcentnum & &quot; || '</OPTION>' from whatever&quot;
set rsAny = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsAny.open strSql, session(&quot;connection&quot;)
Response.Write(rsAny.GetString(2, -1))
rsAny.close
set rsAny = nothing
Response.Write(&quot;</SELECT> &quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top