在asp.net c#中动态填充<img src="?">

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1966584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:16:06  来源:igfitidea点击:

filling <img src="?"> dynamically in asp.net c#

c#asp.net

提问by Shashi

Hi would like to add img source path dynamically as shown in the snippet below, but giving error. I know img_src_path adding syntax is correct. Unfortunately I don't know the solution, need help.

嗨想动态添加 img 源路径,如下面的代码片段所示,但出现错误。我知道 img_src_path 添加语法是正确的。不幸的是我不知道解决方案,需要帮助。

Environment:

环境:

ASP.net, c#

ASP.NET,C#

    <% string a[0]="image/hello.jpg;"
  {
  String img_src_path= a[0].ToString();%>
 <li><a href='"<%#img_src_path%>"'><img src='"<%#img_src_path%>"' alt="" title=""/></a></li>
 <%}%>

/Shashi

/沙市

采纳答案by Hiyasat

replace your code with this:

用这个替换你的代码:

"=" instead of "#"

“=”代替“#”

the solution

解决方案

<li><a href='"<%=img_src_path%>"'><img src='"<%=img_src_path%>"' alt="" title=""/></a></li>

and if you want to edit image src form code behind solution 2:

如果您想编辑解决方案 2 背后的图像 src 表单代码:

<li><a href='"<%=img_src_path%>"'><img src='"<%=img_src_path%>"' id="myImage" runat="server" alt="" title=""/></a></li>

edit image source form codebehind:

编辑图像源表单代码隐藏:

myImage.src = "imagePage";

回答by Gabriel McAdams

The problem is that your image tag does not have a runat="server" attribute (you will also need to add an ID in order to do this).

问题是您的图像标记没有 runat="server" 属性(您还需要添加 ID 才能执行此操作)。

You also need to change your server tags like this:

您还需要像这样更改服务器标签:

FROM:

从:

<%# ... %>

TO:

到:

<%= ... %>

Also, the proper way to do this in ASP.Net would be to use the Image server control.

此外,在 ASP.Net 中执行此操作的正确方法是使用图像服务器控件。

<asp:Image id="Image1" runat="server"></asp:Image>

Then, you would set the NavigateUrl property.

然后,您将设置 NavigateUrl 属性。

回答by HydPhani

The basic error we are trying to workout is Server tags cannot contain <% ... %> constructs.

我们试图解决的基本错误是服务器标签不能包含 <% ... %> 结构。