 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 30th, 2004, 04:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Mateen,
I think you're missing an important concept here. In the example you're trying to get to work, you no longer use the <option elements, but JavaScript code to write out "new ComboBoxItem" stuff. So, you should use server side ASP VBScript to write out client side JavaScript. Something like this should work (haven't tested it or used it, so it may no be error-free):
Code:
<script src="ComboBox.js"></script>
<script>
dm=new ComboBox("dm")
<%
Response.Write("dm.add(" & vbCrLf)
Do While Not rs.EOF
Response.Write("new ComboBoxItem(""" & rs("Name") & """, " & rs("ID") & ")," & vbCrLf)
Loop
Response.Write(")" & vbCrLf)
%>
</script>
This code will loop through your recordset and write out new ComboBoxItem("Name", ID), for each item in your recordset. There is still one little problem you need to tackle: the last item has an ending , as well. You can remove that one by not using Response.Write directly, but by building up a string and then removing the , at the end. You could also change your logic a little so the , is not added when the recordset is EOF.
Does this help? If not, what part do you have troubles with?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

May 31st, 2004, 01:26 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
I use the your coding like this.
<%
dim ssql
set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="" // connection string
cn.Open
%>
Employee Name
<script src="ComboBox. js"></script>
<script> // when I use <script> tage it does not work
render block <% (yellow marks) not generate,
within the <script> tage asp coding can be
use ?
dm=New ComboBox("dm")
<%
ssql="select name from employees order by name"
set rs=cn.Execute(ssql)
Response.Write("dm.add(" & vbCrLf)
Do While Not rs.EOF
Response.Write("new ComboBoxItem(""" & rs("Name") & """, " & rs("ID") & ")," & vbCrLf) // line 59
Loop
Response.Write(")" & vbCrLf)
%>
</script>
but it give following error
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/dcilweb/sas/apprec/combo2c.asp, line 59
rs("name") value recived from the recordset, but how it can the
retrive rs("ID") from the recordset ?
recordset only received name. ID is in the comboBox
regards.
Mateen
Quote:
quote:Originally posted by Imar
Hi Mateen,
I think you're missing an important concept here. In the example you're trying to get to work, you no longer use the <option elements, but JavaScript code to write out "new ComboBoxItem" stuff. So, you should use server side ASP VBScript to write out client side JavaScript. Something like this should work (haven't tested it or used it, so it may no be error-free):
Code:
<script src="ComboBox.js"></script>
<script>
dm=new ComboBox("dm")
<%
Response.Write("dm.add(" & vbCrLf)
Do While Not rs.EOF
Response.Write("new ComboBoxItem(""" & rs("Name") & """, " & rs("ID") & ")," & vbCrLf)
Loop
Response.Write(")" & vbCrLf)
%>
</script>
This code will loop through your recordset and write out new ComboBoxItem("Name", ID), for each item in your recordset. There is still one little problem you need to tackle: the last item has an ending , as well. You can remove that one by not using Response.Write directly, but by building up a string and then removing the , at the end. You could also change your logic a little so the , is not added when the recordset is EOF.
Does this help? If not, what part do you have troubles with?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
|

June 1st, 2004, 03:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Mateen,
When you reply to a message, can please not quote the entire previous message? IMO, it clutters up the forum and is a waste of bandwidth; the previous message is always visible above the latest reply.
Anyway, the code I gave you was just meant as an example; usually when I bind a drop down, I have a Name and an ID field to bind to. The Name is what gets displayed between the <option> tags, and the ID is used as the value attribute.
So, in your case, you should replace rs("Name") and rs("ID") with field names that are appropriate to your situation.
Cheers,
Imar
|
|

June 2nd, 2004, 04:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for response.
I trying but could not success.
which field it couuld be replaced.
regards.
Mateen
|
|

June 2nd, 2004, 05:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You shouldn't ask me as I can't possibly know what fields you are using; you're the one that should make the judgement.
Somehow I think you have a problem understanding how the <select> and <option> elements work. I searched the P2P archives, and you seem to have asked related questions over and over again.
To simplify things; here's a short example:
Code:
<select id="lstTest" name="lstTest">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</select>
In this example, there are two pieces of data: the value of the value attribute (1 and 2 respectively), and the text between the two <option> tags (Item 1 and Item 2 respectively). These are also the pieces of data you need for your custom drop down. The first param is the text, the second is its value:
new ComboBoxItem("Item 1", 1),
new ComboBoxItem("Item 2", 2),
Usually, you would retrieve this information from a table. Suppose you have a table called city. The query SELECT ID, Name FROM City would give you a list with city names and their ID.
If, however, you do not have a unique ID in your table (or, for example, the Name is the unique ID), then simply use the Name column for both pieces of data: The value attribute and the text between the <option> tags.
new ComboBoxItem("Item 1", "Item 1"),
new ComboBoxItem("Item 2", "Item 2"),
If all this doesn't help, I am out of ideas. I think you should get yourself some good books on ASP and XHTML, as they'll definitely clarify some things for you.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 2nd, 2004, 11:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response and sorry for inconvenience to you.
regards.
Mateen
|
|

June 3rd, 2004, 03:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Has the problem been solved now? Does it work?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 5th, 2004, 05:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for response.
problem not solve yet.
I am trying to solve it, as you guide.
it may be possible that I could not properly to explain/describe my
problem and secondly I could not understand to solving it.
although you help me a lot.
regards.
Mateen
|
|

June 5th, 2004, 07:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Mateen,
I created a little article on my site that demonstrates how to create dynamic data for the WebFX control: http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=302
Please note: I am *not* the author of that control. I know nothing about it, so if you need support for it, you'll need to check out the WebFX web site. All I have done is write a little code snippet so you can see how to bind the data from a recordset to the drop-down.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 5th, 2004, 08:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Imar, that was a good job. Nice one.
Cheers!
_________________________
-Vijay G
 Strive for Perfection 
|
|
 |