将 img 添加到 ahref 标签
我希望从我的代码隐藏中完成以下格式:
<a href="">
<img src=""/>
</a>
我已经这样做了,但我无法将图像添加到 谁能告诉我该怎么做?
这是我的代码:
Dim urls As New List(Of String)
urls.Add("Downloads/" & Session("tempDir").ToString & "/" & filename)
For Each imageURL As String In urls
Dim img = New System.Web.UI.WebControls.Image()
img.ImageUrl = imageURL
img.Attributes.Add("src", "Downloads/" & Session("tempDir").ToString & "/" & filename)
img.Attributes.Add("rel", "group2")
img.Width = 75
img.Height = 50
img.CssClass = "clickImage"
img.ImageAlign = HorizontalAlign.Left
Me.FinalPreview.Controls.Add(img)
Next
我发现了这个:
Dim anchor As New HtmlGenericControl("a")
anchor.Attributes.Add("href", "#")
但是我无法理解如何将 img 添加到此如果我添加控制,则总 img 不会显示。
I want the below format to be done from my codebehind:
<a href="">
<img src=""/>
</a>
I have done this way but I am not able to add image to <a href>
Can anyone say me how to do that?
Here is my code:
Dim urls As New List(Of String)
urls.Add("Downloads/" & Session("tempDir").ToString & "/" & filename)
For Each imageURL As String In urls
Dim img = New System.Web.UI.WebControls.Image()
img.ImageUrl = imageURL
img.Attributes.Add("src", "Downloads/" & Session("tempDir").ToString & "/" & filename)
img.Attributes.Add("rel", "group2")
img.Width = 75
img.Height = 50
img.CssClass = "clickImage"
img.ImageAlign = HorizontalAlign.Left
Me.FinalPreview.Controls.Add(img)
Next
I have found this:
Dim anchor As New HtmlGenericControl("a")
anchor.Attributes.Add("href", "#")
But I am not able to understand how do I add img to this If I add control the total img is not showing up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Literal
控件来完成此操作在页面上放置一个文字控件,然后添加其文本,如下所示...
You can do it using
Literal
controlPlace a literal control on the page and then add its text like this...
图像有一个名为 ImageUrl 的特殊属性来设置 URL。
Image has a special property called ImageUrl to set the URL to.