Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Add hyperlinks dynamically - newbie question

Reply
Thread Tools

Add hyperlinks dynamically - newbie question

 
 
JezB
Guest
Posts: n/a
 
      05-24-2004
I have a loop in which I'm adding hyperlinks to a page dynamically :-

foreach (string x in ...)
{
HyperLink h = new HyperLink();
h.Text = x;
h.NavigateUrl = x+".aspx";
this.Controls.Add(h);
}

This works fine but the controls are added one after each other in one long
line. How do I force each one to be displayed on a new line ?


 
Reply With Quote
 
 
 
 
Raterus
Guest
Posts: n/a
 
      05-24-2004
Well, how would you do it in html? use a <br> tag? If you want to that, you'll need to probably use a HtmlGenericControl and set the tagname property. Something like this

foreach (string x in ...)
{
HyperLink h = new HyperLink();
HtmlGenericControl hgc = new HtmlGenericControl();
hgc.tagname="br";
h.Text = x;
h.NavigateUrl = x+".aspx";
this.Controls.Add(h);
this.controls.add(hgc);
}

This is one of I'm sure a ton of ways to change the rendered output. You could also try adding the hyperlink data to an array, and then binding it to a repeater. Lots of options really,

--Michael


"JezB" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I have a loop in which I'm adding hyperlinks to a page dynamically :-
>
> foreach (string x in ...)
> {
> HyperLink h = new HyperLink();
> h.Text = x;
> h.NavigateUrl = x+".aspx";
> this.Controls.Add(h);
> }
>
> This works fine but the controls are added one after each other in one long
> line. How do I force each one to be displayed on a new line ?
>
>

 
Reply With Quote
 
 
 
 
JezB
Guest
Posts: n/a
 
      05-24-2004
I forgot to say, my page is designed in Flow layout.

"JezB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a loop in which I'm adding hyperlinks to a page dynamically :-
>
> foreach (string x in ...)
> {
> HyperLink h = new HyperLink();
> h.Text = x;
> h.NavigateUrl = x+".aspx";
> this.Controls.Add(h);
> }
>
> This works fine but the controls are added one after each other in one

long
> line. How do I force each one to be displayed on a new line ?
>
>



 
Reply With Quote
 
Robert Koritnik
Guest
Posts: n/a
 
      05-25-2004
Insted of this control you can make it even easier (short code):

foreach(string x in ...)
{
HyperLink h = new HyperLink();
h.Text = x;
h.NavigateUrl = x + ".aspx";
this.Controls.Add(h);
this.Controls.Add(new LiteralControl("<br>"));
}

Don't forget to include:
uses System.Web.UI

Or instead you can also change tle last line of code (part) to:
....new System.Web.UI.LiteralControl("<br>")...

--
RobertK
{ Clever? No just smart. }


"Raterus" <(E-Mail Removed)> wrote in message news:#(E-Mail Removed)...
Well, how would you do it in html? use a <br> tag? If you want to that, you'll need to probably use a HtmlGenericControl and set the tagname property. Something like this

foreach (string x in ...)
{
HyperLink h = new HyperLink();
HtmlGenericControl hgc = new HtmlGenericControl();
hgc.tagname="br";
h.Text = x;
h.NavigateUrl = x+".aspx";
this.Controls.Add(h);
this.controls.add(hgc);
}

This is one of I'm sure a ton of ways to change the rendered output. You could also try adding the hyperlink data to an array, and then binding it to a repeater. Lots of options really,

--Michael


"JezB" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I have a loop in which I'm adding hyperlinks to a page dynamically :-
>
> foreach (string x in ...)
> {
> HyperLink h = new HyperLink();
> h.Text = x;
> h.NavigateUrl = x+".aspx";
> this.Controls.Add(h);
> }
>
> This works fine but the controls are added one after each other in one long
> line. How do I force each one to be displayed on a new line ?
>
>

 
Reply With Quote
 
JezB
Guest
Posts: n/a
 
      05-25-2004
Cheers mate



 
Reply With Quote
 
Robert Koritnik
Guest
Posts: n/a
 
      05-25-2004
Thanks. I'll send you the bill for the beer I'll drink on this toast...
Before I get ****ed... ))))

--
RobertK
{ Clever? No just smart. }


"JezB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Cheers mate
>
>
>



 
Reply With Quote
 
Raterus
Guest
Posts: n/a
 
      05-25-2004
Thanks, I'll have to remember that one. I knew there had to be an easier way!
"Robert Koritnik" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Insted of this control you can make it even easier (short code):

foreach(string x in ...)
{
HyperLink h = new HyperLink();
h.Text = x;
h.NavigateUrl = x + ".aspx";
this.Controls.Add(h);
this.Controls.Add(new LiteralControl("<br>"));
}

Don't forget to include:
uses System.Web.UI

Or instead you can also change tle last line of code (part) to:
...new System.Web.UI.LiteralControl("<br>")...

--
RobertK
{ Clever? No just smart. }


"Raterus" <(E-Mail Removed)> wrote in message news:#(E-Mail Removed)...
Well, how would you do it in html? use a <br> tag? If you want to that, you'll need to probably use a HtmlGenericControl and set the tagname property. Something like this

foreach (string x in ...)
{
HyperLink h = new HyperLink();
HtmlGenericControl hgc = new HtmlGenericControl();
hgc.tagname="br";
h.Text = x;
h.NavigateUrl = x+".aspx";
this.Controls.Add(h);
this.controls.add(hgc);
}

This is one of I'm sure a ton of ways to change the rendered output. You could also try adding the hyperlink data to an array, and then binding it to a repeater. Lots of options really,

--Michael


"JezB" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I have a loop in which I'm adding hyperlinks to a page dynamically :-
>
> foreach (string x in ...)
> {
> HyperLink h = new HyperLink();
> h.Text = x;
> h.NavigateUrl = x+".aspx";
> this.Controls.Add(h);
> }
>
> This works fine but the controls are added one after each other in one long
> line. How do I force each one to be displayed on a new line ?
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating hyperlinks dynamically asha ASP .Net 0 10-30-2007 03:10 PM
newbie question on hyperlinks Neil ASP .Net 5 02-20-2007 09:48 AM
dynamically add hyperlinks and buttons to a datagrid Richard Jonker ASP .Net Datagrid Control 2 10-03-2006 05:48 AM
Problem loading asp.net usercontrols dynamically with hyperlinks and images Brett ASP .Net 1 09-09-2004 04:52 AM
Add hyperlinks dynamically - newbie question JezB ASP .Net 6 05-25-2004 08:12 PM



Advertisments