puting a hyperlink in aspx..

  • Thread starter Thread starter naija naija
  • Start date Start date
N

naija naija

Hi All,
I have something like this on my ASPX page

nodeProd.Text = rowProd("ProductName")

I'm getting Data from a table which is ProductName.
How can i input "<a href=""></a> to this if i want the data to have
LINKS.
thanks alot
 
naija naija said:
Hi All,
I have something like this on my ASPX page

nodeProd.Text = rowProd("ProductName")

I'm getting Data from a table which is ProductName.
How can i input "<a href=""></a> to this if i want the data to have
LINKS.

I'm not sure about your request. Could you explain better your situation ?
 
I would like to do something like this if its possible:-


nodeProd.Text = <a href="">rowProd("ProductName")</a>

In short whats the best way to have data populated from the DB to go
straight into a <a href="">ProductName<a/> .

For example have a URL table having - "http://a.aspx"
and the same table having the (ProductName)

So i want to have both the URL and the (ProductName) both populated
from the Database.

So if the URL is http://a.spx and the product name is "bread".
The out come should be <a href="http://a.aspx">bread</a>
 
naijacoder naijacoder said:
I would like to do something like this if its possible:-

nodeProd.Text = <a href="">rowProd("ProductName")</a>
In short whats the best way to have data populated from the DB to go
straight into a <a href="">ProductName<a/> .
For example have a URL table having - "http://a.aspx"
and the same table having the (ProductName)
So i want to have both the URL and the (ProductName) both populated
from the Database.
So if the URL is http://a.spx and the product name is "bread".
The out come should be <a href="http://a.aspx">bread</a>

If you want to retrieve a string, as a final result, this is a simple way to
do that:

nodeProd.Text = this.CreateLink(rowProd("ProductURL"),
rowProd("ProductName"));
private string CreateLink(string url, string text)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<a href='");
sb.Append(url);
sb.Append("'>");
sb.Append(text);
sb.Append(@"</a>");

return sb.ToString();
}

Alternative, if nodeProd has a Controls collection you could add to this
collection an Hyperlink WebControl:
HyperLink lnk = new HyperLink();
lnk.NavigateUrl = rowProd("ProductURL");
lnk.Text = rowProd("ProductName");

nodeProd .Controls.Add(lnk);

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top