473,326 Members | 2,126 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,326 software developers and data experts.

Hyperlink asp control doesn't appear when set

Hi, I've got an XML file with one <title> and one <link> attribute.
What I want to do is implement a hyperlink with the name of the <title> element and whose NavigateUrl property is set to the <link> element.

For an unusual reason, the hyperlink never appears but, when debugged, both items from the XML file are appended to the hyperlink. What have I done wrong?

Cheers,
Matt

Expand|Select|Wrap|Line Numbers
  1. private void ReadXML()
  2.     {
  3.         using (StreamReader sr = File.OpenText(xmlFile))
  4.         {
  5.             while (!sr.EndOfStream && sr.Read() > 0)
  6.             {
  7.                 string line = sr.ReadLine();
  8.                 if (line.Contains("<title>"))
  9.                 {
  10.                     // read until we reach </title>
  11.                     HyperLink4.Text = line.Replace("<title>", ""); // read until <title>
  12.                     HyperLink4.Text = line.Replace("</title>", ""); // read until <title>
  13.                 }
  14.                 // link should follow straight after
  15.                 else if (line.Contains("<link>"))
  16.                 {
  17.                     HyperLink4.NavigateUrl = line.Replace("<link>", "");
  18.                     HyperLink4.NavigateUrl = line.Replace("</link>", ""); // read until <title>
  19.                 }
  20.             }
  21.         }
  22.     }
  23.  
Mar 20 '10 #1
4 2491
jkmyoung
2,057 Expert 2GB
Could you post your input and expected output?
It looks like you have something like
<title>Search</title><link>http://www.google.ca</link>
Which ends up being:
Searchhttp://www.google.ca

Did you want your output in html link form, eg
<a href="http://www.google.ca">Search</a>
or some other different form?
Mar 22 '10 #2
Sure, my input is:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel>
<title>BBC News | UK | UK Edition</title>
<link>http://news.bbc.co.uk/go/rss/-/1/hi/uk/default.stm</link>

<item>
<title>Clegg bids to cool coalition talk</title>
<description>Nick Clegg is to say he is "not the kingmaker" amid speculation about the Lib Dems' possible role in a coalition government.
</description>
<link>http://news.bbc.co.uk/go/rss/-/1/hi/uk_politics/8566448.stm</link>
</item>


An I expect my output to be:

BBC News | UK | UK Edition

http://news.bbc.co.uk/go/rss/-/1/hi/uk/default.stm

Clegg bids to cool coalition talk

Nick Clegg is to say he is "not the kingmaker" amid speculation about the Lib Dems' possible role in a coalition government.

http://news.bbc.co.uk/go/rss/-/1/hi/...cs/8566448.stm

---------------------------
I guess HTML form would be more flexible than an asp:Hyperlink object but it doesn't really matter, I just want to turn the titles within the file into hyperlinks which the user can use to go directly to the report
Mar 22 '10 #3
jkmyoung
2,057 Expert 2GB
Ah, I see, the problem is that you're overwriting it. eg, you'd get

Text = "BBC News | UK | UK Edition</title>" with <title> removed, then
Text = "<title>BBC News | UK | UK Edition" with </title> removed.

Expand|Select|Wrap|Line Numbers
  1. string line = sr.ReadLine(); 
  2. int i = line.IndexOf("<title>");
  3. int j = line.IndexOf("</title>");
  4.  
  5. // If you have a multi-line title, this won't deal with it.
  6. if(i != -1 && j != -1)
  7. {
  8.   HyperLink4.Text = line.Substring(i, j-i);
  9. }
  10.  
and do the same thing with link.

You are assuming each element only comes on one line each, correct?
Mar 22 '10 #4
It's OK, I've solved this by using a better a approach - using Repeaters, Literals and Hyperlinks.

For the benefit of newbies to rss, just like me, this is the site I used:

http://www.wduffy.co.uk/blog/how-to-.../#comment-5101
Mar 24 '10 #5

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

Similar topics

4
by: Andreas Meffert | last post by:
Hello, How can I change the Type of a field in a table from Memo to hyperlink? I import a table from Oracle to Access 2003. After that, the field type of some hyperlink-fields is "Memo". How...
9
by: Leigh Kendall | last post by:
I can't find any issue in the MS KB, but I'm experiencing the following problem which seems to be specific to IE5, and NOT any other version of IE 5.5+ or NN 6+. Issue: I'm using an asp.net...
1
by: Pat | last post by:
How do I trigger the click event of the hyperlink control programmatically? Thanks
0
by: Kevin Quigley | last post by:
Hi, I have a datalist which has an EditItemTemplate section, within this I have a hyperlink control with which I want to open a new window with some help details. This is the hyperlink code:...
8
by: Nathan Sokalski | last post by:
I have several System.Web.UI.WebControls.HyperLink Controls which I want to display as rollover images. I know how to make these manually using the <a> and <img> tags or the <a> tag and a...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
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...
0
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.