473,320 Members | 1,825 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,320 software developers and data experts.

how do i do this, link postback

50
ok, im trying to make a web app using asp.net and vb, what im doing is i have a mysqldatareader reading the database and writing links to the page, what i want to do is when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <a href = "courseinput.aspx">Input</a>
  11. <%  
  12.  
  13.     %>
  14.  
  15.     <form id="form1" runat="server">
  16.     <div>
  17.         Current Courses as of
  18.         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
  19.         <br />
  20.     </div>
  21.     <%  Dim connection As New MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost;Database=sigma;User ID=root;Password=root") 'Provide the connection string to your database
  22.     Dim cmd As MySql.Data.MySqlClient.MySqlCommand
  23.     cmd = New MySql.Data.MySqlClient.MySqlCommand
  24.     cmd.CommandText = "select course from course;"
  25.     connection.Open()
  26.     cmd.Connection = connection
  27.         Dim reader As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
  28. %>
  29.         'this is where the links are posted to the page by the reader
  30.         <% While reader.Read%>
  31.         <ul>
  32.             <li><a href = "#"><%Response.Write(reader(0))%></a></li>
  33.             </ul>
  34.         <%End While%>
  35.  
  36.     </form>
  37. </body>
  38. </html>
  39.  
May 5 '08 #1
11 1149
kenobewan
4,871 Expert 4TB
How do you want to post the data to your new page? If you had a class you could call it from both pages.
ok, im trying to make a web app using asp.net and vb, what im doing is i have a mysqldatareader reading the database and writing links to the page, what i want to do is when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <a href = "courseinput.aspx">Input</a>
  11. <%  
  12.  
  13.     %>
  14.  
  15.     <form id="form1" runat="server">
  16.     <div>
  17.         Current Courses as of
  18.         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
  19.         <br />
  20.     </div>
  21.     <%  Dim connection As New MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost;Database=sigma;User ID=root;Password=root") 'Provide the connection string to your database
  22.     Dim cmd As MySql.Data.MySqlClient.MySqlCommand
  23.     cmd = New MySql.Data.MySqlClient.MySqlCommand
  24.     cmd.CommandText = "select course from course;"
  25.     connection.Open()
  26.     cmd.Connection = connection
  27.         Dim reader As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
  28. %>
  29.         'this is where the links are posted to the page by the reader
  30.         <% While reader.Read%>
  31.         <ul>
  32.             <li><a href = "#"><%Response.Write(reader(0))%></a></li>
  33.             </ul>
  34.         <%End While%>
  35.  
  36.     </form>
  37. </body>
  38. </html>
  39.  
May 5 '08 #2
jarremw
50
i would like to post it using the datareader and let the reader read everything to the new page, something like when the user clicks on the link it will search the db for the row associated with that string of text and post it to another page called post where there would be labels to fill in for each part found in the db

basically, i am wanting to know what link is clicked by the user so i can get the link text, search the db, and post to a new page with the information, sorry if im not being clear enough, ive been trying to do postback but cant really find anything that deals with links...

so the events would be
link is clicked
link text is stored in a string
connect to db
search for row associated with string
send to new page called post.aspx
return the results from the db for the link
May 5 '08 #3
Curtis Rutland
3,256 Expert 2GB
...when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous
Why not let the other page do the reading? Use a querystring/session object to pass the key information to the next page and let that page do the actual selecting. No need to pass large amounts of data from page to page.
May 5 '08 #4
jarremw
50
ok, i just looked around on that, but how would handle this when the reader is creating the link for me?

while reader.read
<a href = "post.aspx" lname = "<% response.write(reader(0)) %>
end while

i have the reader creating the link for me from each row in the db so that means that essentailly every link would be same right?, so how would i handle this event? or will the page know what linked was click so that when i call for the querystring, it will have the clicked links text
May 5 '08 #5
Curtis Rutland
3,256 Expert 2GB
ok, i just looked around on that, but how would handle this when the reader is creating the link for me?

while reader.read
<a href = "post.aspx" lname = "<% response.write(reader(0)) %>
end while

i have the reader creating the link for me from each row in the db so that means that essentailly every link would be same right?, so how would i handle this event? or will the page know what linked was click so that when i call for the querystring, it will have the clicked links text

Can't you set the value of that reader to a variable, and then use the variable to build your link and link text? I'm not too familiar with the way you are doing things, this looks more like classic ASP.
May 5 '08 #6
jarremw
50
yeah im just now learning asp.net, ive been doing vb for about 8 months, what methods would i use to do this in asp.net? basically what should i google because ive been looking around, i just dont know really what to look for, about the only thing that i have seen is postback stuff but that sounds like a lot to do for my webapp...

thanks for the quick replies...
May 5 '08 #7
Curtis Rutland
3,256 Expert 2GB
yeah im just now learning asp.net, ive been doing vb for about 8 months, what methods would i use to do this in asp.net? basically what should i google because ive been looking around, i just dont know really what to look for, about the only thing that i have seen is postback stuff but that sounds like a lot to do for my webapp...

thanks for the quick replies...
Look up SqlDataSource, and Repeater, for starters. These are really useful for what you need. That would likely be how I would do it. Just set up your sql statement to select the key column (like an id or something) and then the other data you want. Then use the repeater to make a repeating list of links. Use the key data for the link itself, like:
post.aspx?id=value
And use the other info for the link text.

Here's some sample code from one of my applications that uses the SqlDataSource and Repeater controls:
Expand|Select|Wrap|Line Numbers
  1. <asp:SqlDataSource ID="sd1" runat="server" ConnectionString="<%$ ConnectionStrings:AccessConnectionString %>"
  2.         SelectCommand="SELECT [idDepartment], [dept] FROM [departments]"></asp:SqlDataSource>
  3.     <asp:Repeater ID="Repeater1" runat="server" DataSourceID="sd1">
  4.         <ItemTemplate>
  5.             <a href="test.aspx?id=<%# Eval("iddepartment") %>">
  6.                 <%# Eval("dept") %>
  7.             </a>
  8.             <br />
  9.         </ItemTemplate>
  10.     </asp:Repeater>
  11.  
What you would want to do is go into Design mode, and then drag a SqlDataSource onto the page. Then configure it, and then drag a repeater onto the page. Set the repeater's datasource to the id of the SqlDataSource you just used. Then use the <%# Eval("value") %> (replace value with the column name) to return the value for that row.

Just google for them to get more familiar with it.
May 5 '08 #8
jarremw
50
so will this help me with the links? like if i display just the title of the course on the page and when they click on the title link, it gets the rows associated with that clicked link and displays the info on another page?
May 5 '08 #9
Curtis Rutland
3,256 Expert 2GB
so will this help me with the links? like if i display just the title of the course on the page and when they click on the title link, it gets the rows associated with that clicked link and displays the info on another page?
Are you trying to list courses on one page, and then display information about the selected course on another? If so, then yes, this can do that. Basically all this is doing is generating links for you. On your next page, you have to handle that. You can get to the value stored in the querystring using this:
if your link is:
post.aspx?id=123
use
Request.QueryString("id")

That would return 123. Then use a select statement to get all the data you need for that record and populate the controls on the page.


If you learn a little more about these controls and how to use them, you will see how they apply to this situation.
May 5 '08 #10
jarremw
50
ok thank you so much, i finally understand this (kinda) haha thanks for the help and the quick replies, i love this site
May 5 '08 #11
jarremw
50
so i have a strange problem now, ive got the repeater to connect to my mysql db and fill in my links, now my problem is when i pass the querystring......when set a labels text property to the querystring, it comes out right, but when i try to include in a sql statement something like
select * from course where course = '" & this is the variable that holds my requested querystring & "' and run it through a data reader and nothing comes out at all, ive tried in both a page_load event and in the source of the page....any ideas?
May 6 '08 #12

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

Similar topics

5
by: Matt | last post by:
I always see the term "postback" from ASP book, but I am not sure if I fully understand the meaning. Here's my understanding so far, please correct me if any mistakes. Here's a typical html...
5
by: Matthew Louden | last post by:
I created simple ASP.NET web application to test how AutoPostBack property in a web control works. I set AutoPostBack property to be true of a web control. When I run the application, here's the...
1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
1
by: M | last post by:
It's possible to call a Page PostBack with a link (<a href='....'>link</a>)? I would like only to add to the QueryString a parameter (i.e. PageN=3 ) and then calling a PostBack Can I do...
1
by: Craig G | last post by:
i havent a clue about javascript, i found a small snippet for launching a datetimepicker, ive used the following to successfully open a small dialog window for a calender. i want to do something...
3
by: Alejandro Penate-Diaz | last post by:
Hi. I have posted this question three times in this newsgroup as well as microsoft.public.scripting.jscript and have get no answer yet. Now I dont know if my question is too stupid or too weird,...
2
by: Brian Henry | last post by:
I want to put some interactivity on my form in the form of buttons that are really links, I know i can do a query string in the link to process their action based on the type of action specified in...
0
by: graphicsxp | last post by:
Hi, WebPage Description: Contains one datagrid with link button column and one gridview with dropdownlist column. <asp:LinkButton id="QueryName" runat="server" autopostback="true"...
1
by: shapper | last post by:
Hello, I need to create a data object to hold a number of records with 3 columns. A datatable would do. My problem is this: 1. I will use this as a GridView datasource. 2. I will need to...
4
by: tiago.private | last post by:
Hi everybody, Imagine the following scenario: One System.Web.UI.UserControl (UC1) with 2 drop downs and one button "Filter" One Webform with (UC1) and a GridView, basically the UC1 provides...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
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
0
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...

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.