473,839 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two column data in a single list box

subashini Thiyagarajan
218 New Member
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 5568
jhardman
3,406 Recognized Expert Specialist
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
subashini Thiyagarajan
218 New Member
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 Recognized Expert Specialist
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
subashini Thiyagarajan
218 New Member
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 Recognized Expert Specialist
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
subashini Thiyagarajan
218 New Member
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 Recognized Expert Specialist
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
subashini Thiyagarajan
218 New Member
hi,
thanks for your mail.i am doing project in asp.
Mar 18 '07 #9
cognac
4 New Member
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(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
Mar 30 '07 #10

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

Similar topics

1
9914
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 created a function using VBA to achieve a more dynamic (and very slow) solution.. so I would like to implement it using a user defined function in sql server. The problems I'm facing are, that I can't use dynamic sql in a
8
11603
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 be updated when a group of items is copied. I can successfully do this with cursors, but am experimenting with a way to do it with a single update statement. I have verified that each row being returned to the Update statement (in an...
20
2777
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 normalized data. The task is made more difficult by the fact that the structure itself can vary from month to month (in well defined ways). So, I used the SQL-centric approach, taking vertical stripes at a time so that, for instance, for each...
2
1756
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, Aravind.
2
2774
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 information into three separate tables (all in a single aspx page -- without using stored procedures, yet). The first SQL Statement accepts the persons most detailed information, like name, address, phone, etc and inserts the single record into...
6
2437
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 and runs it cannot add any additional information (like a WHERE clause). I need to add a few more records to the the table, and would like the query to include a value from another field in the current row in a WHERE clause -- something like...
6
2568
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 select the column orders. Instead the datasource is a class which implements IList, containing a collection of my data. My problem again is that I don't know how to control the order of the columns that are exported.
1
1842
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 for my purposes: $columns = 3; $query = Non Admins; $result = mysql_query($query); $num_rows = mysql_num_rows($result); //we are going to set a new variables called $rows
6
2359
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 columns but to keep them invisible until a selection is made from the select list. Once a selection has been made then the remaining column's data is made visible alongside the select list and concatenated into a comma separated single field for...
3
1721
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 the dropdown box ok when it was outside of the gridview for (int i = 0; i <= listcategory.Count - 1; i++) { ddl.Items.Add(listcategory.Description);
0
9856
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9429
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4494
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.