Solved

adding li to the ul from server side code

Posted on 2012-03-13
4
1,858 Views
Last Modified: 2012-04-11
I am trying to add li to ul from code behind.  Following is the html I have currently. I need to move this to vb.net

 <ul id="mycarousel" runat ="server"  class="jcarousel-skin-tango">       
        <li><a href = "/rebate/b0" ><img src="/Assets/Rebate/PaperClipsEtc100.jpg" style="background-color:#E7E7E9;padding:4px;border:1px solid #D6D7D9;" /></a></li>            
    </ul>      
I started of with this , but I dont see the image. Please help

     For countRebate As Integer = 0 To dtRebates.Rows.Count - 1
                Dim liCarousel As New HTMLGENriccontrol
                mycarousel.Controls.Add(liCarousel)

                Dim anchorCarousel As New HtmlAnchor
                anchorCarousel.Attributes.Add("href", "/rebate/b" & dtRebates.Rows(countRebate)("BrandID"))
                liCarousel.Controls.Add(anchorCarousel)

                Dim imgCarousel As New HtmlImage
                imgCarousel.Attributes.Add("src", "/Assets/images/products/mfglogos/3M_LOGO.jpg")
                anchorCarousel.Controls.Add(imgCarousel)
            Next
0
Comment
Question by:TrialUser
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points
ID: 37717397
Why add the src by adding to the Attributes collection? The HtmlImage class exposes the Src property which you can assign to:

anchorCarousel.Src = Server.MapPath("/Assets/images/products/mfglogos/3M_LOGO.jpg")

Open in new window


Side comment: Same as the above:  You shouldn't have to do the add attribute logic in order to set the anchor's HREF--there should be a property named Href which can use.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37717669
Have you seen the source that's rendered in browser? Can you show the relevant parts here?
0
 
LVL 11

Accepted Solution

by:
SAMIR BHOGAYTA earned 167 total points
ID: 37718289
Hello,

You have to put one literal control. Then after pass the ul and li into this literal like this.

literal.Text = "<ul><li></li></ul>"
0
 
LVL 9

Assisted Solution

by:sarabhai
sarabhai earned 166 total points
ID: 37718629
Dim ul As HtmlGenericControl = DirectCast(Page.FindControl("mycarousel"), HtmlGenericControl)
        Dim liToAdd As New HtmlGenericControl("li")
        liToAdd.InnerText = "Test"
        ul.Controls.Add(liToAdd)


try to add <image> inside the liToAdd control.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question