【问题标题】:Server tag not well formed on asp:image of gridviewASP 上的服务器标签格式不正确:gridview 的图像
【发布时间】:2013-03-29 02:57:52
【问题描述】:

对我应该使用 Eval 还是 Bind 感到困惑。我阅读了很多关于这个主题的答案,但似乎没有一个是我的具体情况。此链接上的答案应该可以工作,但没有

How to display image in gridview from server floder?

这是我最初尝试的,我没有收到错误,但我没有让图片显示在网格中。

    <asp:TemplateField HeaderText="Image" SortExpression="Image" HeaderStyle-Width="250" >
      <ItemTemplate>
        <asp:Image runat="server" ID="imagePreview"  Width="200" ImageUrl='~/ProductImages/ <%# Bind("Filename") %>' />
      </ItemTemplate>
    </asp:TemplateField>

然后我尝试按照上面链接中的建议将我的 asp:image 标记重新编码为以下内容

&lt;asp:Image runat="server" ID="imagePreview" Width="200" ImageUrl="&lt;%# Page.ResolveClientUrl(String.Format("~/ProductImages/{0}",Eval("Filename"))) %&gt;" /&gt;

但这给了我一个

“服务器标签格式不正确”

错误。

我也尝试了使用标签的建议,但也无法使用该方法。

是否可以在不在文件后面的代码中设置图像 url 和 asp:image 标记的情况下执行此操作,还是必须使用 img 标记?

谢谢

【问题讨论】:

    标签: c# asp.net gridview imageurl


    【解决方案1】:

    通过图片 url lyk this....

    ImageUrl='<%# "~/ProductImages/"+Eval("Filename").ToString() %>' 
    

    【讨论】:

    • 这很好用。我也很喜欢这个地方。我以你的方式发送良好的业力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 2010-10-15
    • 2012-12-14
    • 1970-01-01
    相关资源
    最近更新 更多