Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. dynamically adding links

dynamically adding links

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi all, This is probably a easy one for someone out there and im hoping that someone can help me as it has been doing my head in for two days. What im trying to do is dynamically add several links in a bullet point form on a aspx page from the code behind file. the problem is that i have mouse over events associated with the link which will display a image in a desinated picture box on the form which relates to the link. All the information about the link including image url is coming from a class that is populated from the database. What i can do: I can add the link in a lable control or place holder control using the: lable.controls.add(asplink) but this only puts the link in the lable but not in bullet point form. Please help. Thanks inadvance

    S 1 Reply Last reply
    0
    • L Lost User

      Hi all, This is probably a easy one for someone out there and im hoping that someone can help me as it has been doing my head in for two days. What im trying to do is dynamically add several links in a bullet point form on a aspx page from the code behind file. the problem is that i have mouse over events associated with the link which will display a image in a desinated picture box on the form which relates to the link. All the information about the link including image url is coming from a class that is populated from the database. What i can do: I can add the link in a lable control or place holder control using the: lable.controls.add(asplink) but this only puts the link in the lable but not in bullet point form. Please help. Thanks inadvance

      S Offline
      S Offline
      StylezHouse
      wrote on last edited by
      #2

      Create a class that inherits the hyperlink or label. Give it the extra properties you need it to display. And make it render them properly. Use that class inside of a repeater, and databind a collection to it. Probably a ton of ways to implement what you want, but I think at first glance, that's the route I'd take.

      L 1 Reply Last reply
      0
      • S StylezHouse

        Create a class that inherits the hyperlink or label. Give it the extra properties you need it to display. And make it render them properly. Use that class inside of a repeater, and databind a collection to it. Probably a ton of ways to implement what you want, but I think at first glance, that's the route I'd take.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks so much for the reply. Greatly appreciated! Only thing is never used a repeater and not sure how that going to put my links within the html* tags: Here is my code, hopefully you can understand what i want to do. if(!IsPostBack) { dbnews = new NewsManip(); //class that contains methods to get data #region Product News ArrayList newslist = new ArrayList(dbnews.GetHomeProductNews()); //Get arraylist which contains a list of classes with links information imgProdNews.ImageUrl = "/img/news/productnews.gif"; Label newslinks = new Label(); newslinks.Text = " "; HyperLink testlink; foreach(News curr in newslist) { newslinks.Text += "* "; testlink = new HyperLink(); testlink.ID = "link"+curr.NewsId.ToString(); testlink.NavigateUrl = "#"; testlink.Text = curr.NewsHeadline; testlink.Attributes.Add("onMouseOver", (imgProdNews.ClientID + ".src=\'"+curr.NewsImageUrl+"'; window.status=\'"+testlink.NavigateUrl+"'; return true;")); testlink.Attributes.Add("onMouseOut", (imgProdNews.ClientID + ".src=\'/img/news/productnews.gif'; window.status=\'\'; return true;")); newslinks.Controls.Add(testlink); newslinks.Text += " "; } newslinks.Text += " "; phProdNews.Controls.Add(newslinks); //Add lable to the place holders basically i need the format to look like:
        * Dynamic link 1
        * Dynamic link 2
        * Dynamic link 3Again thank you for your help.

        S 1 Reply Last reply
        0
        • L Lost User

          Thanks so much for the reply. Greatly appreciated! Only thing is never used a repeater and not sure how that going to put my links within the html* tags: Here is my code, hopefully you can understand what i want to do. if(!IsPostBack) { dbnews = new NewsManip(); //class that contains methods to get data #region Product News ArrayList newslist = new ArrayList(dbnews.GetHomeProductNews()); //Get arraylist which contains a list of classes with links information imgProdNews.ImageUrl = "/img/news/productnews.gif"; Label newslinks = new Label(); newslinks.Text = " "; HyperLink testlink; foreach(News curr in newslist) { newslinks.Text += "* "; testlink = new HyperLink(); testlink.ID = "link"+curr.NewsId.ToString(); testlink.NavigateUrl = "#"; testlink.Text = curr.NewsHeadline; testlink.Attributes.Add("onMouseOver", (imgProdNews.ClientID + ".src=\'"+curr.NewsImageUrl+"'; window.status=\'"+testlink.NavigateUrl+"'; return true;")); testlink.Attributes.Add("onMouseOut", (imgProdNews.ClientID + ".src=\'/img/news/productnews.gif'; window.status=\'\'; return true;")); newslinks.Controls.Add(testlink); newslinks.Text += " "; } newslinks.Text += " "; phProdNews.Controls.Add(newslinks); //Add lable to the place holders basically i need the format to look like:
          * Dynamic link 1
          * Dynamic link 2
          * Dynamic link 3Again thank you for your help.

          S Offline
          S Offline
          StylezHouse
          wrote on last edited by
          #4

          Here's a pretty good example on using the repeater control. http://www.asp101.com/articles/john/repeater/default.asp That should help you out. And it seems you need to create a class called NewsLink that inherits Hyperlink. That has additional properties of OnMouseOver, and OnMouseOut, and when those values aren't empty, they are applied to itself. Use that inside of your repeater, with an unordered list, and you'll be good to go.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups