473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

<a href> & <asp:Hyperlink>

Consider the following code:

<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim sqlReader As SqlDataReader

sqlReader = 'calling a function that returns SqlDataReader

dlCart.DataSource = sqlReader
dlCart.DataBind
End Sub
</script>
<form runat="server">
<asp:DataList ID="dlCart" runat="server">
<HeaderTemplate>
<table>
<tr>
........
........
........
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItem("ProdID") %></td>
<td><%# Container.DataItem("ProductName") %></td>
<td><%# Container.DataItem("Price") %></td>
<td><a href='RemoveItem.aspx?ProdID=<%# Container.DataItem("ProdID")
%>'>Remove</a></td>
</tr>
</ItemTemplate>
......
</asp:DataList>
</form>

Assume that the DataList displays 3 products to a user. The ProdIDs of
the 3 products are 10, 20 & 30 respectively.

When the user clicks the product whose ProdID is 10, as expected, he is
taken to RemoveItem.aspx with the querystring ProdID=10 appended to it
i.e. the user is taken to

http://myserver/RemoveItem.aspx?ProdID=10

But instead of using <a href...for rendering the 'Remove' link, if I
use <asp:Hyperlink>

<td><asp:Hyperlink ID="lnk" NavigateUrl='RemoveItem.aspx?ProdID=<%#
Container.DataItem("ProdID") %>' Text="Remove" runat="server"/></td>

then <%# Container.DataItem("ProdID") %doesn't get assigned to the
appropriate ProdID. Rather, the URL of link literally remains as what
is coded above (using <asp:Hyperlink..>). In other words, irrespective
of whichever 'Remove' link a user clicks, he is taken to

http://myserver/RemoveItem.aspx?ProdID=<%#%20Container.DataItem("P rodID")%20%>

How do I use <%# Container.DataItem("ProdID") %in the NavigateUrl
property of <asp:Hyperlinkin order to assign the corresponding
database ProdID value to the querystring ProdID so that, for e.g. if
the user clicks the 'Remove' link corresponding to the product whose
ProdID is 10, he is taken to

http://myserver/RemoveItem.aspx?ProdID=10

Oct 1 '06 #1
1 5711
http://weblogs.asp.net/rajbk/archive...20/188868.aspx
<rn**@rediffmail.comwrote in message news:11**********************@i3g2000cwc.googlegro ups.com...
Consider the following code:

<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim sqlReader As SqlDataReader

sqlReader = 'calling a function that returns SqlDataReader

dlCart.DataSource = sqlReader
dlCart.DataBind
End Sub
</script>
<form runat="server">
<asp:DataList ID="dlCart" runat="server">
<HeaderTemplate>
<table>
<tr>
.......
.......
.......
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItem("ProdID") %></td>
<td><%# Container.DataItem("ProductName") %></td>
<td><%# Container.DataItem("Price") %></td>
<td><a href='RemoveItem.aspx?ProdID=<%# Container.DataItem("ProdID")
%>'>Remove</a></td>
</tr>
</ItemTemplate>
.....
</asp:DataList>
</form>

Assume that the DataList displays 3 products to a user. The ProdIDs of
the 3 products are 10, 20 & 30 respectively.

When the user clicks the product whose ProdID is 10, as expected, he is
taken to RemoveItem.aspx with the querystring ProdID=10 appended to it
i.e. the user is taken to

http://myserver/RemoveItem.aspx?ProdID=10

But instead of using <a href...for rendering the 'Remove' link, if I
use <asp:Hyperlink>

<td><asp:Hyperlink ID="lnk" NavigateUrl='RemoveItem.aspx?ProdID=<%#
Container.DataItem("ProdID") %>' Text="Remove" runat="server"/></td>

then <%# Container.DataItem("ProdID") %doesn't get assigned to the
appropriate ProdID. Rather, the URL of link literally remains as what
is coded above (using <asp:Hyperlink..>). In other words, irrespective
of whichever 'Remove' link a user clicks, he is taken to

http://myserver/RemoveItem.aspx?ProdID=<%#%20Container.DataItem("P rodID")%20%>

How do I use <%# Container.DataItem("ProdID") %in the NavigateUrl
property of <asp:Hyperlinkin order to assign the corresponding
database ProdID value to the querystring ProdID so that, for e.g. if
the user clicks the 'Remove' link corresponding to the product whose
ProdID is 10, he is taken to

http://myserver/RemoveItem.aspx?ProdID=10

Oct 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steve Chatham | last post by:
This ought to be simple, but I've not been able to figure out how to do this. I have a request to create a list from a sql database to be displayed in a datagrid on an asp web page. So far,...
3
by: Henry Johnson | last post by:
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically populate a table cell as follows (from C# code-behind)? I've tried using a Literal control in the...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
13
by: tperri | last post by:
I have an HTML table with several fields like this: <A href="Savings.aspx?category=Food"><asp:imagebutton id="imgFood" ImageUrl="images\buttons\btn-food-i.gif"...
7
by: Axel Dahmen | last post by:
Hi, within a DataGrid control I'm using a DataTable containing a string column to fill a Hyperlink's href attribute. Unfortunately HttpUtility.UrlEncode() doesn't escape the apostroph character,...
10
by: Lorie0114 | last post by:
Hello, We have an issue that I do not know how to resolve. Our website has several hundred reports. There are a handful of them that are causing issues when there is no interaction for a couple...
4
by: maz77 | last post by:
Hi! I'd like to know what's the difference between <a runat="server" href="tmp.aspx"and <Hyperlink NavigateUrl="tmp.aspx"in VisualStudio2005. What's the better chice? Thanks Max
6
by: Jose Santos | last post by:
I am using a very useful application known as GenericDB by Eli Robillard. I have a classic ASP application that requires that when a specific field contains user comments (not empty) pertaining to a...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.