Hi,
I am lost when it comes to creating a click event in asp.
I have hyperlinks that are pulled dynamically from a table. An example is Hockey is a hyperlink.
What I want to do is when a user selects the Hockey link, information regarding Hockey will be pulled from another table and displayed on a page.
In order to do this, I have to create the click event for when the user selects the hyperlink Hockey it will pull the info from the Subprograms table.
My problem is I don't know how to refer to the click event with the hyperlink.
Here is my code that created the hyperlinks. - <%
-
Dim conn, rs, query
-
if request.querystring("display") = "Programs" then
-
'Create an ADODB connection
-
Set conn = Server.CreateObject("ADODB.Connection")
-
-
'Open the database
-
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentre;UID=myUserID;PWD=myPWD;"
-
-
'Execute the SQL and assign to our Recordset
-
set rs = Server.createobject("ADODB.recordset")
-
query = "SELECT description FROM programtbl"
-
-
LinkChosen=Programs">Programs</a>
-
-
rs.Open query, conn%>
-
<%response.write "<br>"& vbNewLine
-
-
-
do until rs.eof %>
-
-
<a href="ValourCC.asp?program=<%=rs("description")%>"><%=rs("description")%></a>
-
-
-
-
<%
-
-
rs.MoveNext
-
loop
-
end if
-
%>
-
-
</div>
Public Program click_event ?????
6 2382
Mona,
I've removed your password and user name from your code. Please notice that this is a public forum and posting you user name and password is a potentially serious security risk.
The thing is, I'm not sure you want to create a click event (whatever that means to you). It looks to me like you want to link to a second page (called "valourCC.asp?program=hockey") when you click the link. On this second page you can now open the database with something like this: - query = "SELECT * FROM myTable WHERE description = '"
-
query = query & request.querystring("program") & "'"
-
-
rs.open query, conn
Does this make sense?
Jared
Thanks,
I'll try it out and let you know.
Mona
Hi,
So far I have a Programs hyperlink that is working by pulling the info from the programs table which is Sports, Youth Programming, etc.
Now I have to get the code to work when the Sports link is selected I would like to pull the information from the Subprogramstbl. There is a heading in the subprogramstbl called Sports.
Under this heading there are fields of sports such as baseball and hockey.
When I select the Sports link nothing happens. Baseball and Hockey are not displayed.
This is what I have. - <%
-
Dim conn, rs, query
-
if request.querystring("display") = "Programs" then
-
'Create an ADODB connection
-
Set conn = Server.CreateObject("ADODB.Connection")
-
-
'Open the database
-
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=?????;Database=communitycentre;UID=???;PWD=???;"
-
-
'Execute the SQL and assign to our Recordset
-
set rs = Server.createobject("ADODB.recordset")
-
query = "SELECT description FROM programtbl"
-
-
' Dim selected, query
-
' get the item that was passed in the querystring.
-
' selected = Request.QueryString("LinkChosen")
-
-
-
' <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>
-
-
rs.Open query, conn%>
-
<% response.write "<br>"& vbNewLine
-
-
-
do until rs.eof %>
-
-
<a href="ValourCC.asp?program=<%=rs("description")%>"><%=rs("description")%></a>
-
-
-
-
<%
-
-
rs.MoveNext
-
loop
-
end if
-
%>
-
-
</div>
-
-
-
<%
-
if request.querystring("display") = "Sports" then
-
-
'Create an ADODB connection
-
Set conn = Server.CreateObject("ADODB.Connection")
-
-
'Open the database
-
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=???;Database=communitycentre;UID=????;PWD=???;"
-
-
'Execute the SQL and assign to our Recordset
-
set rs = Server.createobject("ADODB.recordset")
-
query = "SELECT Sports from Subprogramstbl"
-
query = query & request.QueryString ("sports") & "'"
-
-
rs.Open query, conn%>
-
<% response.write "<br>"& vbNewLine%>
-
-
-
<%do until rs.eof%>
-
<a href="ValourCC.asp?program=<%=rs("sports")%>"><%=rs("sports")%></a>
-
-
<%
-
-
rs.MoveNext
-
loop
-
end if
-
%>
Thanks for all your help. I think I would rip my hair out if I didn't have your help.
You are on the right track. I think one of the things that is confusing you is that to connect with a database you need to use a different language altogether from the ASP (vbscript) language. This other "language" is "SQL" and it is just a standard way to send a request to a database, and any db should be able to understand the request and give you the results. The lines where you say "query = ..." you are making a SQL query. The basic syntax is: - SELECT fieldName1, fieldName2 FROM myDatabaseTable WHERE fieldName3 = 'happy'
This will pull up two fields (fieldName1, fieldName2) from every record where fieldName3 = "happy". Does this make sense? Notice that SQL is almost readable English. Your lines 52 and 53 make this SQL query which is obviously in bad syntax: - SELECT Sports from Subprogramstblfootball'
We make this kind of mistake all the time. Experienced programmers like to print out this line so we can read it. The code for printing it out would be: - response.write "<br>" & query & "<br>" & vbNewLine
Looking at the above SQL query, you should recognize that there is something wrong, even if you are not sure what the correct query should be. Do you agree? The correct query should look something like this: - SELECT Sports FROM Subprogramstbl WHERE fieldName1 = 'football'
Notice that this will make the db give you the field "Sports" from every record where fieldName1 = 'football'. I'm not sure this is what you want. It is likely that you want every field from the records where the field "Sports" equals 'football'. If this is the case, the query should look like this: - SELECT * FROM Subprogramstbl WHERE Sports = 'football'
Does this syntax make sense? To make the ASP code form this query, I would write it like this: - query = "SELECT * FROM Subprogramstbl WHERE Sports = '"
-
query = query & request.QueryString ("sports") & "'"
Look through this and make sure everything I said makes sense. Try it out and see what you get.
Jared
Hi,
I understand what you are saying for the sql code.
I want all the fields under the heading sports to be displayed as links. Same as how I displayed the hyperlinks under Programs.
So now when the user selects the programs hyperlink, sports, youth programming links are displayed.
Now when the user selects sports hyperlink they want to see what sports are offered. I've went over my code, and everything looks fine except when I click on the sports hyperlink. The fields under Sports are not displaying.
I thought it was because my response.write code was not working properly, but it looks fine.
I've attached the code again, to see if you can see what the problem is.
<%
Dim conn, rs, query
if request.querystring("display") = "Programs" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")
'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=????PWD=???;"
'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT description FROM programtbl"
' Dim selected, query
' get the item that was passed in the querystring.
' selected = Request.QueryString("LinkChosen")
' <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>
rs.Open query, conn%>
<% response.write "<br>"& vbNewLine
do until rs.eof %>
<a href="ValourCC.asp?program=<%=rs("description")%>" ><%=rs("description")%></a>
<%
rs.MoveNext
loop
end if
%>
<%
if request.querystring("display") = "Sports" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")
'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=???;PWD=???;"
'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT Sports from Subprogramstbl"
query = query & request.QueryString ("sports") & " ' "
rs.Open query, conn
response.write "<br>" & query & "<br>" & vbNewLine
do until rs.eof%>
<a href="ValourCC.asp?sports=<%=rs("sports")%>"><%=rs ("sports")%></a>
<%
rs.MoveNext
loop
end if
%>
Hi,
I understand what you are saying for the sql code.
I want all the fields under the heading sports to be displayed as links. Same as how I displayed the hyperlinks under Programs.
So now when the user selects the programs hyperlink, sports, youth programming links are displayed.
Now when the user selects sports hyperlink they want to see what sports are offered. I've went over my code, and everything looks fine except when I click on the sports hyperlink. The fields under Sports are not displaying.
I thought it was because my response.write code was not working properly, but it looks fine.
I've attached the code again, to see if you can see what the problem is.
<%
Dim conn, rs, query
if request.querystring("display") = "Programs" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")
'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=????PWD=???;"
'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT description FROM programtbl"
' Dim selected, query
' get the item that was passed in the querystring.
' selected = Request.QueryString("LinkChosen")
' <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>
rs.Open query, conn%>
<% response.write "<br>"& vbNewLine
do until rs.eof %>
<a href="ValourCC.asp?program=<%=rs("description")%>" ><%=rs("description")%></a>
<%
rs.MoveNext
loop
end if
%>
<%
if request.querystring("display") = "Sports" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")
'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=???;PWD=???;"
'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT Sports from Subprogramstbl"
query = query & request.QueryString ("sports") & " ' "
rs.Open query, conn
response.write "<br>" & query & "<br>" & vbNewLine
do until rs.eof%>
<a href="ValourCC.asp?sports=<%=rs("sports")%>"><%=rs ("sports")%></a>
<%
rs.MoveNext
loop
end if
%>
--------------------------------------------------------------------------------
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pat |
last post by:
How do I trigger the click event of the hyperlink control
programmatically?
Thanks
|
by: |
last post by:
Does anyone know how to trigger the click event of a
hyperlink control programmatically?
Thanks for helping.
|
by: Doug Stiers |
last post by:
I have an asp:hyperlink that I need to have some code fire when the link is
clicked. The link is in a datagrid and the link is working properly. I tried
using the OnInit event to call the...
|
by: |
last post by:
Hi
I am using vb.net code behind.
In my code I have a button click event on my main web
form.
Private Sub btNew_Click(ByVal sender As System.Object,
ByVal e As
System.EventArgs) Handles...
|
by: Allan Ebdrup |
last post by:
Why doesn't the Hyperlink Control have a serverside click event?
I would like to run some serverside code when a user clicks on a link, do I
really have to insert a button and format it as a...
|
by: samuelberthelot |
last post by:
Hi,
Hi have a hyperlink column in my datagridview. How can I capture the
click event on the hyperlink ?
Thank you
|
by: smHaig |
last post by:
Not being an web programmer I am unable to figure out how to put the
hyperlink mailto:emailaddress in a button click event. I do not want a
hyperlink on the form. I have found nothing to address...
|
by: nani |
last post by:
Hi friends
I am creating one web application in that i take one hyperlink
control.when i click hyperlink control.how to split the page in two
parts and display the result in that secound part
If...
|
by: SAL |
last post by:
Hello,
I'm working, basically my first, AJAX page and am having a few problems.
One is that the Click event for a button I have in UpdatePanel1 is not
getting called. I've tried with the button...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |