Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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
 
Old May 30th, 2004, 04:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old May 31st, 2004, 01:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 1st, 2004, 03:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
 
Old June 2nd, 2004, 04:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response.

I trying but could not success.
which field it couuld be replaced.

regards.

Mateen


 
Old June 2nd, 2004, 05:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old June 2nd, 2004, 11:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response and sorry for inconvenience to you.

regards.

Mateen


 
Old June 3rd, 2004, 03:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Has the problem been solved now? Does it work?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 5th, 2004, 05:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






 
Old June 5th, 2004, 07:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old June 5th, 2004, 08:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Imar, that was a good job. Nice one.

Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Employee attendance form with DataGridView Dot_Net_Dev C# 3 June 8th, 2011 02:25 AM
Select the top 3 record of each employee phungleon Access 1 June 16th, 2007 01:16 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
When I hit save button the selected employee clear shoakat Classic ASP Databases 6 September 16th, 2004 01:41 AM
Spelling BruceFraser BOOK: Professional Crystal Reports for VS.NET 0 August 25th, 2003 12:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.