【发布时间】:2020-03-24 01:40:09
【问题描述】:
我是 VB 的新手,所以如果我的术语在 VB 方面不是最好的,我提前道歉。
我有一个 href 链接,我目前正在尝试使其动态化。以前我尝试使用asp:HyperLink,但我遇到了超链接问题,因为我无法链接标题并一直看到example-link.com 而不是VIEW ARTICLE。
我已经进行了一些研究,并且似乎使用字符串构建器方法可以获得我期望的结果。我目前遇到了字符串生成器的问题。
以下是我想要完成的任务的细分
我尝试动态重新创建的静态链接示例。
<i class="fa fa-chevron-right"></i><a href="/how-to-develop/" target="_self" title="How to Develop">VIEW ARTICLE</a>
我对 ASP:HyperLink 的尝试:
<asp:HyperLink ID="MyListUrl" runat="server">View Article</asp:HyperLink>
超链接的代码隐藏
Public Class Links
Public Property MyListId As Integer
Public Property MyListRecommendation As String
Public Property MyListSummary As String
Public Property MyListUrl As String
End Class
Protected Sub InitializeTrendsListsObject()
If MyLists.MyListId = 1 Then ' How to Develop
MyLists.MyListUrl = "/how-to-develop/"
ElseIf MyLists.MyListId = 2 Then ' How to Code
MyLists.MyListUrl = "/how-to-code/"
End Sub
我对字符串生成器的尝试:
<i class="fa fa-chevron-right"></i><asp:Literal ID="ltMyListURL" runat="server"></asp:Literal>
后面的代码
Protected Overloads Function BuildRecommendation (ByVal reports As DataTable, ByVal counter As Integer, ByVal isExec As Boolean) As String
Dim htmlBuilder As New StringBuilder
Dim endLoop As Integer = 1
If isExec Then
For Each report As DataRow In reports.Rows
If Not endLoop.Equals(counter) Then
htmlBuilder.AppendLine("<p class='trends-list-item-summary'>" + report(2).ToString() + "... <a
class='trends-list-item-more' href='" + MyList.MyListUrl+ report(3).ToString() + "/'
target='_blank' title='" + report(0).ToString() + "'>View Article</a></p>")
endLoop += 1 ' increment controller by 1
Else
Exit For
End If
Next
' Close content container
htmlBuilder.AppendLine("</div>")
End If
Return htmlBuilder.ToString()
End Function
【问题讨论】:
标签: vb.net dynamic href stringbuilder