How to default select the last item of a list box

How to default select the last item of a list box

Post by Martin Bélange » Tue, 29 Feb 2000 04:00:00



I have a list box that contain db fields. Like that:

<html>
<SELECT name=cbofrom style="HEIGHT: 22px; WIDTH: 100px">
<%call fillcbogl%>
</SELECT>
</html>

.................

<SCRIPT LANGUAGE=vbscript runat=server>
sub fillcbogl ()
   if not(oRS.EOF and oRS.BOF) then
      oRS.MoveFirst
      do while not oRS.EOF
       Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
       Response.Write oRS("GL_ACCT")
       Response.Write "</OPTION>"
       oRS.MoveNext
       'this count is doing because is not seem to have a listcount in
vbscript
      Loop
   end if
end sub
</SCRIPT>

but i want to select by default the last item of the combo.... how i can do
that????

tanx a lot

 
 
 

How to default select the last item of a list box

Post by Naveh Bara » Tue, 29 Feb 2000 04:00:00


                 if oRs.AbsolutePosition = oRs.recordcount then
                Response.Write "<OPTION SELECTED VALUE='" & oRS("GL_ACCT") &
"'>"
                else
                Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
                end if


Quote:> I have a list box that contain db fields. Like that:

> <html>
> <SELECT name=cbofrom style="HEIGHT: 22px; WIDTH: 100px">
> <%call fillcbogl%>
> </SELECT>
> </html>

> .................

> <SCRIPT LANGUAGE=vbscript runat=server>
> sub fillcbogl ()
>    if not(oRS.EOF and oRS.BOF) then
>       oRS.MoveFirst
>       do while not oRS.EOF
>        Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
>        Response.Write oRS("GL_ACCT")
>        Response.Write "</OPTION>"
>        oRS.MoveNext
>        'this count is doing because is not seem to have a listcount in
> vbscript
>       Loop
>    end if
> end sub
> </SCRIPT>

> but i want to select by default the last item of the combo.... how i can
do
> that????

> tanx a lot


 
 
 

How to default select the last item of a list box

Post by Anil Batr » Tue, 29 Feb 2000 04:00:00


You can do a count on your query and then use that count to know where your
last record is

strCount = "Select count(1) from table_name"
 Then open this record set get count , now you know how many rows are coming
back.  Then use a counter in your Loop to see when you reach your last
record.


Quote:> I have a list box that contain db fields. Like that:

> <html>
> <SELECT name=cbofrom style="HEIGHT: 22px; WIDTH: 100px">
> <%call fillcbogl%>
> </SELECT>
> </html>

> .................

> <SCRIPT LANGUAGE=vbscript runat=server>
> sub fillcbogl ()
>    if not(oRS.EOF and oRS.BOF) then
>       oRS.MoveFirst
>       do while not oRS.EOF
>        Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
>        Response.Write oRS("GL_ACCT")
>        Response.Write "</OPTION>"
>        oRS.MoveNext
>        'this count is doing because is not seem to have a listcount in
> vbscript
>       Loop
>    end if
> end sub
> </SCRIPT>

> but i want to select by default the last item of the combo.... how i can
do
> that????

> tanx a lot

 
 
 

How to default select the last item of a list box

Post by Scott » Tue, 29 Feb 2000 04:00:00


Or perhaps try moving the oRS.MoveNext statement above
Response.Write("</OPTION>", and testing for EOF.  If EOF is true write out "
selected" (with the leading space).  Something like this:

    do while not oRS.EOF
       Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
       Response.Write oRS("GL_ACCT")
       oRS.MoveNext
       if oRS.EOF Then Response.Write " selected"
       Response.Write "</OPTION>"
    loop


Quote:> I have a list box that contain db fields. Like that:

> <html>
> <SELECT name=cbofrom style="HEIGHT: 22px; WIDTH: 100px">
> <%call fillcbogl%>
> </SELECT>
> </html>

> .................

> <SCRIPT LANGUAGE=vbscript runat=server>
> sub fillcbogl ()
>    if not(oRS.EOF and oRS.BOF) then
>       oRS.MoveFirst
>       do while not oRS.EOF
>        Response.Write "<OPTION VALUE='" & oRS("GL_ACCT") & "'>"
>        Response.Write oRS("GL_ACCT")
>        Response.Write "</OPTION>"
>        oRS.MoveNext
>        'this count is doing because is not seem to have a listcount in
> vbscript
>       Loop
>    end if
> end sub
> </SCRIPT>

> but i want to select by default the last item of the combo.... how i can
do
> that????

> tanx a lot

 
 
 

1. Selecting Items from a multi select list box VC++ 6.0 on W2K

Being an entry level programmer with no mentor or real
Visual C++(6.0) education this application has been a
challenge and my current one is:
I have a new dialog box that has a multi select list box
that is populated with (toll free)numbers pulled from a
SQLServer database.  Now I am trying to take the numbers I
have selected and put them into the report table in the
database.
On my GetSelected function I am getting an assert fail and
I'm sure my pointers or references are wrong but not sure
where.  All I can say is I obviously don't teach myself
very well.  Any assistance would be greatly appreciated.

void CDNISNumSelect::GetSelected(CStringList
*strlDNISNumbers)
{
        int selectedArray = NULL;      
        int totalSize= m_lbDNISNumbers->GetSelCount();      
        // it counts what I have selected
        //CListBox* m_lbDNISNumbers = (CListBox*)
        //GetDlgItem(IDC_DNISNUMSELECT_LIST);
        CString strSpace(" ");
        int selectSize = m_lbDNISNumbers->GetSelect
(totalSize, selectedArray);  // gets an assert fail here

        strlDNISNumbers = new CStringList(selectSize);
        CString *temp;

        for (int k = 0; k < selectSize; k++)        

        {              
                temp = (CString *)m_lbDNISNumbers-
                strlDNISNumbers->AddTail(*temp);
        }

2. Btrieve and WinFrame?

3. send list box item to my default printer

4. JSP - JDBC connection problem

5. Removing multiple selected items from VB5 List Boxes

6. install failed (SQL 7), "encryption not supported"...

7. Getting query output to a file?

8. List Box VFP5.0 - Selecting an item

9. Selecting Items in a List box

10. Selecting record in a List Box after items rearranged

11. Selecting the last record in a list box

12. Toggling Between List Boxes at the Same Location and Selecting Records in Each List Box