Two column data in a single list box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • subashini Thiyagarajan
    New Member
    • Dec 2006
    • 218

    Two column data in a single list box

    Hi ,

    Can any one help me how to populate two column details in a single list box using asp and access.

    pls help me

    thanks
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Hi suba,

    You're not entirely clear. I have populated a select list from three columns of a db (fields were named idNum, fName, and lName).

    Code:
    do until objRS.eof %>
       <option value="<%=objRS("idNum")%>"><%=objRS("fName") & " " & objRS("lName")%></select>
       <%
       objRS.moveNext
    loop %>
    Is this what you wanted? There is a good demo at webwizguide

    Jared

    Comment

    • subashini Thiyagarajan
      New Member
      • Dec 2006
      • 218

      #3
      Hi Jared,

      what i exactly mean is if one column has data of 1 2 3
      and another column has 5 6 7

      i wanted to display in a list box to contain 1 2 3 5 6 7 as 6 no of data.

      is it possible? how to do? pls

      thanks

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        and you want to list them in that order? I guess you have a few options. this would work:
        Code:
        dim firstHalfString, secondHalf
        do until objRS.eof
           firstHalfString = firstHalfString & "<option value=" & chr(34) &_
              objRS("col1") & chr(34) & ">" & objRS("col1") & "</option>" & vbNewLine
           secondHalf = secondHalf & "<option value=" & chr(34) & objRS("col2") &_
              chr(34) & ">" & objRS("col2") & "</option>" & vbNewLine
           objRS.moveNext
        loop %>
        <select name="myCombinedSelect">
        <%=firstHalfString%>
        <%=secondHalf%>
        </select>
        Jared

        Comment

        • subashini Thiyagarajan
          New Member
          • Dec 2006
          • 218

          #5
          hi,

          i have succeded of my own attempt,see the below code it works fine

          Code:
           <select id="select2" name="SortLocation" onChange="">
              <option><%=SortLocation%></option>
              <%
                '-- Populate drop-down list from Products table.
                Set CNObj = Server.CreateObject("ADODB.Connection")
                CNObj.Open "DBQ=C:\Inetpub\wwwroot\manage\fiber\fiber.mdb; DRIVER=Microsoft Access Driver (*.mdb)"
                Set RSOption = Server.CreateObject("ADODB.Recordset")
                SQL = "SELECT Distinct loca FROM e1"
                RSOption.Open SQL, CNObj
                Do While Not RSOption.EOF %>
              <option><%=RSOption.Fields("loca")%></option>
              <% RSOption.MoveNext
                Loop
                RSOption.Close
                CNObj.Close
                %>
          	  <%
                '-- Populate drop-down list from Products table.
                Set CNObj = Server.CreateObject("ADODB.Connection")
                CNObj.Open "DBQ=C:\Inetpub\wwwroot\manage\fiber\fiber.mdb; DRIVER=Microsoft Access Driver (*.mdb)"
                Set RSOption = Server.CreateObject("ADODB.Recordset")
                SQL = "SELECT Distinct locb FROM e1"
                RSOption.Open SQL, CNObj
                Do While Not RSOption.EOF %>
              <option><%=RSOption.Fields("locb")%></option>
              <% RSOption.MoveNext
                Loop
                RSOption.Close
                CNObj.Close
                %>
            </select>

          now the problem is i got distinct data from both,but their is soem unique data in both column how to restrict ?

          any help


          in mean column 1- 1 2 3 4
          column 2 - 2 3 5 7

          2,3 is common in both i don't want the repetition again.
          my data shows as per the above code 1 2 3 4 2 3 5 7

          any help

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by subashini Thiyagarajan
            2,3 is common in both i don't want the repetition again.
            my data shows as per the above code 1 2 3 4 2 3 5 7

            any help
            Is the data in any format that could easily be sorted? (numerical or I guess even alpha numeric?)
            Jared

            Comment

            • subashini Thiyagarajan
              New Member
              • Dec 2006
              • 218

              #7
              hi jared,

              you are asking doubt to me or u r giving suggestion to me.i could not get what u r trying to explain.u r from which country

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                Originally posted by subashini Thiyagarajan
                hi jared,

                Either you are expressing a doubt or you are giving me a suggestion. I could not get what you are trying to explain. From which country do you hail?

                Subashini
                Suba,

                I am from the United States. Once again, is the data in a format that can be sorted? If so, put it in an array before you put it in the drop down box, sort the array, then when you scroll through it check for double entries like this:
                Code:
                response.write "<option>" & myOptions(0) & "</option>" & vbNewLine
                i = 1
                do while i <= ubound(myOptions)
                   if myOptions(i) <> myOptions(i-1) then
                      response.write "<option>" & myOptions(i) & "</option>" & vbNewLine
                   end if
                   i = i + 1
                loop
                Does this make sense?

                Jared

                Comment

                • subashini Thiyagarajan
                  New Member
                  • Dec 2006
                  • 218

                  #9
                  hi,
                  thanks for your mail.i am doing project in asp.

                  Comment

                  • cognac
                    New Member
                    • Mar 2007
                    • 4

                    #10
                    Originally posted by jhardman
                    and you want to list them in that order? I guess you have a few options. this would work:
                    Code:
                    dim firstHalfString, secondHalf
                    do until objRS.eof
                       firstHalfString = firstHalfString & "<option value=" & chr(34) &_
                          objRS("col1") & chr(34) & ">" & objRS("col1") & "</option>" & vbNewLine
                       secondHalf = secondHalf & "<option value=" & chr(34) & objRS("col2") &_
                          chr(34) & ">" & objRS("col2") & "</option>" & vbNewLine
                       objRS.moveNext
                    loop %>
                    <select name="myCombinedSelect">
                    <%=firstHalfString%>
                    <%=secondHalf%>
                    </select>
                    Jared

                    Hi Jared,
                    I was looking for same kind of code but not this code for one of my project problems.. What I have is..
                    One drop down box two list boxes..
                    Based on the drop down box value the sub categories of that value are displayed in the listbox(say listbox1)... Now i let user choose from my listbox1 a value and add it to second listbox value(say listbox2)
                    what i want is ..
                    if the drop down box has values say Countries..and listbox1 has provinces corresponding to the country chosen ... is user chooses two Provinces from one country and three provinces from another then the display on the third list box should be:
                    Country1 : Province1
                    Province2

                    Country2: Province 1
                    Province2
                    Province3
                    and so on... is it possible..??
                    the snippet of my code is :

                    <!-------- Drop Down box ------------>
                    <% SQL= "select * from dacategory"
                    set category= conn.execute(SQ L)%>
                    <Select onchange="init( );" name="category" style="width:au to">
                    <%Do While not Category.Eof%>
                    <%If UCase(Trim(LocC ategory))=UCase (Trim(category( "category_id")) ) then%>
                    <Option Value="<%=categ ory("category_i d")%>" selected><%=cat egory("category ")%></Option>
                    <%else%>
                    <Option Value="<%=categ ory("category_i d")%>" ><%=category("c ategory")%></Option>
                    <%End If%>
                    <% category.MoveNe xt%>
                    <%Loop%>
                    </Select>
                    <% category.close
                    set category=nothin g%>

                    <!-------- List Box1 ------------->
                    <% SQL="select * from da_static_flds where category_id="&l occategory
                    set flds= conn.execute(SQ L)%>
                    <select name="fields" multiple="multi ple" style="width:au to" size="9" >
                    <%do while not flds.eof%>
                    <Option Value="<%=flds( "fld_id")%>"><% =flds("field_na me")%></Option>
                    <% flds.movenext
                    loop
                    flds.close
                    set flds=nothing
                    %>
                    </select>

                    <!------------- Buttons to add and remove ---------->
                    <input onclick="addtol ist();" type="button" name="add" value=" Add &gt;&gt;" /><br /><input name="remove" onclick="remove fromlist();" type="button" value="&lt;&lt; Remove" />

                    <!------------ Listbox2 -------------------->
                    <select name="selected" multiple="multi ple" style="width:in herit" size="9" >
                    <option value=""></option>
                    </select>
                    <input type="hidden" name="temp" value="" />
                    <input type="hidden" name="Action" value="0" />
                    </form>

                    <!----------------- Javascript for functions ------------>

                    <script language="javas cript">
                    function addtolist()
                    {
                    var Flds=document.f rm.fields;
                    var SelFlds=documen t.frm.selected;
                    for (i=0;i<Flds.len gth;i++)
                    {
                    if (Flds[i].selected==true )
                    {
                    var chk=0;
                    var tmp="";
                    for (j=0;j<SelFlds. length;j++) {
                    if(SelFlds[j].text==Flds[i].text)
                    { chk=1;}}
                    if(chk==0)
                    {
                    SelFlds.options[SelFlds.length]=new Option(Flds[i].text);
                    alert(SelFlds.l ength)
                    SelFlds.options[SelFlds.length-1].value = Flds[i].value;
                    }
                    fillTmp();
                    }
                    }

                    }
                    function fillTmp() {
                    var SelFlds = document.frm.se lected;
                    var tmp = "";
                    for (j=0;j<SelFlds. length;j++) {
                    if (tmp=="") {
                    tmp = SelFlds[j].value;
                    }
                    else {
                    tmp = tmp+","+SelFlds[j].value;
                    }
                    }
                    document.frm.te mp.value = tmp;
                    }

                    function removeFromList( ) {
                    var SelFlds = document.frm.se lected;
                    for (i=0;i<SelFlds. length;i++) {
                    if (SelFlds[i].selected==true ) {
                    SelFlds[i]=null;
                    i=0;
                    }
                    }
                    fillTmp();
                    }
                    </script>

                    Thanks
                    Cognac

                    Comment

                    • jhardman
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3405

                      #11
                      Originally posted by cognac
                      Hi Jared,
                      I was looking for same kind of code but not this code for one of my project problems.. What I have is..
                      One drop down box two list boxes..
                      Based on the drop down box value the sub categories of that value are displayed in the listbox(say listbox1)... Now i let user choose from my listbox1 a value and add it to second listbox value(say listbox2)
                      what i want is ..
                      if the drop down box has values say Countries..and listbox1 has provinces corresponding to the country chosen ... is user chooses two Provinces from one country and three provinces from another then the display on the third list box should be:
                      Country1 : Province1
                      Province2

                      Country2: Province 1
                      Province2
                      Province3
                      and so on... is it possible..??
                      the snippet of my code is :

                      Thanks
                      Cognac
                      Cognac,
                      two questions before I start:

                      -How much is up and working? ALthough I can often muscle-through javascript, I am not fluent, and I'm not sure I can see what you are doing. Are you saying the first part is working (selecting the country and province) but you can't get the third list produced?

                      - And you want to do this in asp rather than javascript? Please confirm.

                      Jared

                      Comment

                      • cognac
                        New Member
                        • Mar 2007
                        • 4

                        #12
                        Originally posted by jhardman
                        Cognac,
                        two questions before I start:

                        -How much is up and working? ALthough I can often muscle-through javascript, I am not fluent, and I'm not sure I can see what you are doing. Are you saying the first part is working (selecting the country and province) but you can't get the third list produced?

                        - And you want to do this in asp rather than javascript? Please confirm.

                        Jared
                        Ok what I mean is..
                        I am able to select the "category" from the drop down box.. and list the subcategories in listbox1 according to dropdown and select from listbox1 to listbox2 ..for user to choose using add button.. I can see the values in listbox2..
                        now when i remove it from listbox2 in case user doesnt want them.... It doesnt work.. using the remove button..
                        although i can see the values in Listbox2 .. ...but cant remove them.. from listbox2...
                        wish you were here to see what i am doing..
                        lemme try again..
                        you must have seen recruitement websites asking us to fill their registeration form.. in which they ask us to select subject thats we know..under a category...
                        like under database we have Oracle, SQL, MYSQL, Foxpro..
                        they let us choose categories (like database) from drop down and the they dynamically list..the subjects in listbox(MYSQL,M S SQL Server,ORACLE) and then they ask us to select from that listbox to another listbox where we can arrange according to degree or level of knowledge we have.. like if i know Oracle well then i can bring it to the top but hitting the up arrow key..if i know linux well then i can bring linux after oracle... and so on..
                        thats the concept i am following..
                        hope you know what i mean now..
                        Please try to help..
                        i already posted the snippet of my code..
                        now i am not able to remove from the selected subcategories box..as explained before..
                        Thanks

                        Sania

                        Comment

                        • cognac
                          New Member
                          • Mar 2007
                          • 4

                          #13
                          Originally posted by jhardman
                          Cognac,
                          two questions before I start:

                          -How much is up and working? ALthough I can often muscle-through javascript, I am not fluent, and I'm not sure I can see what you are doing. Are you saying the first part is working (selecting the country and province) but you can't get the third list produced?

                          - And you want to do this in asp rather than javascript? Please confirm.

                          Jared
                          I want to do it using ASP and javascript both..

                          Comment

                          • cognac
                            New Member
                            • Mar 2007
                            • 4

                            #14
                            Originally posted by jhardman
                            Cognac,
                            two questions before I start:

                            -How much is up and working? ALthough I can often muscle-through javascript, I am not fluent, and I'm not sure I can see what you are doing. Are you saying the first part is working (selecting the country and province) but you can't get the third list produced?

                            - And you want to do this in asp rather than javascript? Please confirm.

                            Jared
                            Jared
                            GRRRRRRRRRRRR !!!!!! @ me
                            You know what...
                            everything works now..
                            and you know why it wasnt working??
                            if youwill know you would be like ... HUHHHHHHHH ??????
                            anyways..
                            this isnt the first time I am forgetting stupid stuff like this ..
                            I usually try to not forget Javascript is case sensitive...
                            but at times.. my brain freezes...
                            anyhow... thanks
                            sorry to bother you..
                            My Bad..
                            *-*
                            tc
                            Cognac

                            Comment

                            Working...