473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 5541
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

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

Similar topics

1
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
2
by: Aravind | last post by:
Hi guys, Is there any way to access the full column form a table into a List Box..If you have some samle codes ..plz forward them..thats very useful for me to refer.. Thanks in Advance,...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
6
by: Steve | last post by:
I realize that this probably isn't a best practice, but I'm working with legacy code that has a query stored in one column of a table. Because the queries vary, the JSP page that selects a query...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
1
LuiePL
by: LuiePL | last post by:
I'm looking to update my member list, Since certain states will have more members, I've decided to go with a "single list" approach. I found the following code from this site, which I have modified...
6
by: garwil | last post by:
Hi, I have a table with the following columns. code, class, nobeds, bedtype, sleeps I have made column "code" into a select list and am trying to figure a way to join it to the other...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a generic list of data list <typelistcategory; listcategory = new list <type>; I also have a dropdown box that I have put into a template column of a gridview. I was able to populate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.