469,318 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,318 developers. It's quick & easy.

Two column data in a single list box

subashini Thiyagarajan
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
Mar 12 '07 #1
13 5301
jhardman
3,406 Expert 2GB
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).

Expand|Select|Wrap|Line Numbers
  1. do until objRS.eof %>
  2.    <option value="<%=objRS("idNum")%>"><%=objRS("fName") & " " & objRS("lName")%></select>
  3.    <%
  4.    objRS.moveNext
  5. loop %>
Is this what you wanted? There is a good demo at webwizguide

Jared
Mar 13 '07 #2
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
Mar 14 '07 #3
jhardman
3,406 Expert 2GB
and you want to list them in that order? I guess you have a few options. this would work:
Expand|Select|Wrap|Line Numbers
  1. dim firstHalfString, secondHalf
  2. do until objRS.eof
  3.    firstHalfString = firstHalfString & "<option value=" & chr(34) &_
  4.       objRS("col1") & chr(34) & ">" & objRS("col1") & "</option>" & vbNewLine
  5.    secondHalf = secondHalf & "<option value=" & chr(34) & objRS("col2") &_
  6.       chr(34) & ">" & objRS("col2") & "</option>" & vbNewLine
  7.    objRS.moveNext
  8. loop %>
  9. <select name="myCombinedSelect">
  10. <%=firstHalfString%>
  11. <%=secondHalf%>
  12. </select>
  13.  
Jared
Mar 14 '07 #4
hi,

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

Expand|Select|Wrap|Line Numbers
  1.  <select id="select2" name="SortLocation" onChange="">
  2.     <option><%=SortLocation%></option>
  3.     <%
  4.       '-- Populate drop-down list from Products table.
  5.       Set CNObj = Server.CreateObject("ADODB.Connection")
  6.       CNObj.Open "DBQ=C:\Inetpub\wwwroot\manage\fiber\fiber.mdb; DRIVER=Microsoft Access Driver (*.mdb)"
  7.       Set RSOption = Server.CreateObject("ADODB.Recordset")
  8.       SQL = "SELECT Distinct loca FROM e1"
  9.       RSOption.Open SQL, CNObj
  10.       Do While Not RSOption.EOF %>
  11.     <option><%=RSOption.Fields("loca")%></option>
  12.     <% RSOption.MoveNext
  13.       Loop
  14.       RSOption.Close
  15.       CNObj.Close
  16.       %>
  17.       <%
  18.       '-- Populate drop-down list from Products table.
  19.       Set CNObj = Server.CreateObject("ADODB.Connection")
  20.       CNObj.Open "DBQ=C:\Inetpub\wwwroot\manage\fiber\fiber.mdb; DRIVER=Microsoft Access Driver (*.mdb)"
  21.       Set RSOption = Server.CreateObject("ADODB.Recordset")
  22.       SQL = "SELECT Distinct locb FROM e1"
  23.       RSOption.Open SQL, CNObj
  24.       Do While Not RSOption.EOF %>
  25.     <option><%=RSOption.Fields("locb")%></option>
  26.     <% RSOption.MoveNext
  27.       Loop
  28.       RSOption.Close
  29.       CNObj.Close
  30.       %>
  31.   </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
Mar 14 '07 #5
jhardman
3,406 Expert 2GB
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
Mar 14 '07 #6
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
Mar 15 '07 #7
jhardman
3,406 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. response.write "<option>" & myOptions(0) & "</option>" & vbNewLine
  2. i = 1
  3. do while i <= ubound(myOptions)
  4.    if myOptions(i) <> myOptions(i-1) then
  5.       response.write "<option>" & myOptions(i) & "</option>" & vbNewLine
  6.    end if
  7.    i = i + 1
  8. loop
Does this make sense?

Jared
Mar 16 '07 #8
hi,
thanks for your mail.i am doing project in asp.
Mar 18 '07 #9
cognac
4
and you want to list them in that order? I guess you have a few options. this would work:
Expand|Select|Wrap|Line Numbers
  1. dim firstHalfString, secondHalf
  2. do until objRS.eof
  3.    firstHalfString = firstHalfString & "<option value=" & chr(34) &_
  4.       objRS("col1") & chr(34) & ">" & objRS("col1") & "</option>" & vbNewLine
  5.    secondHalf = secondHalf & "<option value=" & chr(34) & objRS("col2") &_
  6.       chr(34) & ">" & objRS("col2") & "</option>" & vbNewLine
  7.    objRS.moveNext
  8. loop %>
  9. <select name="myCombinedSelect">
  10. <%=firstHalfString%>
  11. <%=secondHalf%>
  12. </select>
  13.  
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(SQL)%>
<Select onchange="init();" name="category" style="width:auto">
<%Do While not Category.Eof%>
<%If UCase(Trim(LocCategory))=UCase(Trim(category("cate gory_id"))) then%>
<Option Value="<%=category("category_id")%>" selected><%=category("category")%></Option>
<%else%>
<Option Value="<%=category("category_id")%>" ><%=category("category")%></Option>
<%End If%>
<% category.MoveNext%>
<%Loop%>
</Select>
<% category.close
set category=nothing%>

<!-------- List Box1 ------------->
<% SQL="select * from da_static_flds where category_id="&loccategory
set flds= conn.execute(SQL)%>
<select name="fields" multiple="multiple" style="width:auto" size="9" >
<%do while not flds.eof%>
<Option Value="<%=flds("fld_id")%>"><%=flds("field_name")% ></Option>
<% flds.movenext
loop
flds.close
set flds=nothing
%>
</select>

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

<!------------ Listbox2 -------------------->
<select name="selected" multiple="multiple" style="width:inherit" 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="javascript">
function addtolist()
{
var Flds=document.frm.fields;
var SelFlds=document.frm.selected;
for (i=0;i<Flds.length;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.length)
SelFlds.options[SelFlds.length-1].value = Flds[i].value;
}
fillTmp();
}
}

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

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

Thanks
Cognac
Mar 30 '07 #10
jhardman
3,406 Expert 2GB
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
Mar 31 '07 #11
cognac
4
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,MS 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
Apr 2 '07 #12
cognac
4
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..
Apr 2 '07 #13
cognac
4
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
Apr 2 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Aravind | last post: by
6 posts views Thread by Opa | last post: by
3 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.