1

I have a web form but I have to do this by code since I dont know the number of hyperlinks I need from the beginning.

How can I add some hyperlinks with Image in a label, the number of hyperlink depends on the number of rows of a query, and each row give me the link information to navigate.

Thanks in advance.

1
  • can you please explain it clearly. can't understand what you want to do. Commented Jun 15, 2011 at 14:40

2 Answers 2

2

As you loop through your data you can manually add a link to the row something like this:

       For i As Integer = 0 To 10
            Dim row As New HtmlTableRow
            row.Cells.Add(New HtmlTableCell)

            Dim Link As New HyperLink
            Link.Text = "WhateverText"
            Link.NavigateUrl = "page.aspx"
            Link.ImageUrl = "~/Theme/Images/SomeImage.gif"
            Link.ToolTip = "ToolTipText"
            row.Cells(0).Controls.Add(Link)
        Next

That of course adds the link as the first cell in an html table. Not sure how you plan to display your data.

In response to the comment below. You can instead insert the new cell something like this

        For i As Integer = 0 To 10
            Dim row As New HtmlTableRow
            Dim cell As New HtmlTableCell
            row.Cells.Insert(1, cell)
            Dim Link As New HyperLink
            Link.Text = "WhateverText"
            Link.NavigateUrl = "page.aspx"
            Link.ImageUrl = "~/Theme/Images/SomeImage.gif"
            Link.ToolTip = "ToolTipText"
            row.Cells(0).Controls.Add(Link)
        Next

You could also simply add the control to the existing cell that the label is in instead of making a new cell. You can do that by the index value of your existing cell (starting at 0 for each cell that is in the row)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but I have a label like this:.... lblInfo.text="<TD>" + "Info" +</TD></TR> , How Can I Add a HyperLink with Image after </TD> and before the </TR>
0

This question is similar to what you want to do: Auto increment asp control ID

Two options either use a repeater or dynamically add the controls to a panel or some other container control.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.