Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlinks in Repeater Control from Access Data Source 1

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I hope somoene out there can assist me. I am trying to convert my ASP skills to ASP.Net. I am using Expression Web as my IDE.

I have created a web page that successfully connects to an Access Datasource. I am querying "announcement" information which has a field for hyperlinks. The results of my query are passed to a Repeater Control.

All of my data is displayed properly except for the hyperlinks. What is displayed by the repeater control is the hyperlink surrounded by # signs.

Example: #
When I hover my mouse over the link I can see the link path actually shows the site name and then the link, again surrounded in # signs.

Example:
I have tried the suggestions in thread855-1294230 but no luck. Can anyone tell me what I am doing wrong?

Here are the bits of relevent code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>

<script language ="vbscript" runat="server">
sub Page_Load
	dim dbconn,sql,dbcomm,dbread
	dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/fpdb/announcements.mdb"))
	dbconn.Open()
	sql="SELECT StartDate, Subject, Announcement, link FROM Results WHERE StartDate <= Now AND EndDate >= Now ORDER BY 1 DESC"
	dbcomm=New OleDbCommand(sql,dbconn)
	dbread=dbcomm.ExecuteReader()
	announcements.DataSource=dbread
	announcements.DataBind()
	dbread.Close()
	dbconn.Close()
end sub
</script>

Code:
<form runat="server">
			<asp:Repeater id="announcements" runat="server">
			<HeaderTemplate>
				<table border="1" width="100%">
			</HeaderTemplate>
					<ItemTemplate>
						<tr>
							<td><%#Container.DataItem("StartDate")%>&nbsp; <%#Container.DataItem("Subject")%></td>
						</tr>
						<tr bgcolor="white">
							<td><%#Container.DataItem("Announcement")%></td>
						</tr>
						<tr bgcolor="silver">
						<td>
						<asp:HyperLink id="hyperlink1" 
                  NavigateUrl=<%# DataBinder.Eval(Container.DataItem, "link") %> 
                  Text=<%# DataBinder.Eval(Container.DataItem, "link") %> 
                  runat="server"/>

						</td>
						</tr>
				</ItemTemplate>
					<FooterTemplate>
					</table>
				</FooterTemplate>
			</asp:Repeater>
		</form>

Best regards,

Mark
 
A follow up. First regardign the code posted, not sure how the Attachmate Solutions got in there, strange cut and paste from the the referenced thread I think.

Anyway, I made some progress in isolating this a bit, but I have no idea how to fix it.

Using the above code works great if the database filed being queried is just a text field. In my case the URLs are in fact stored in a hyperlink field in Access.

So it looks like my revised question is how do you query a hyperlink field in Access and have the resulting links be properly displayed using a repeater control?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
try wrapping all the attributes with ' ' ( single quotes)

i think VS/ asp.net has an issue with using " " in repeater items, because you're using "" in you Eval item.
 
Hmm, I'm not sure how ASP.NET would deal with a Hyperlink field. I think I'd be tempted to convert the hyperlink value to a string in the SQL Statement. A simple test that I've just done seemed to work by using:
Code:
SELECT Left(Cstr(FIELDNAME),Instr(Cstr(FIELDNAME), '#')-1) As MyLink
FROM Table1;
Then I can just bind directly to that field.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Thanks Mark. A direct copy/paste of what you suggested did not do the trick but it did help me get the the solution. Here is the select statement that did the trick.

Code:
	sql="SELECT StartDate, Subject, Announcement, [red]Mid(Cstr(link),2,Len(Cstr(link))-2) As MyLink[/red] FROM Results WHERE StartDate <= Now AND EndDate >= Now ORDER BY 1 DESC"

Nick, I tried what you suggested also but got an error "expression expected."

Thank you both for your assistance.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top