【问题标题】:Use of ImageButton without ImageURL to display the image使用不带 ImageURL 的 ImageButton 来显示图像
【发布时间】:2012-03-28 18:48:18
【问题描述】:

我需要使用 asp 控件“ImageButton”才能访问属性“OnClick”和“OnClientClick”

问题是我无法提供任何 ImageURL,因为我的图片在数据库中。

我以前用过这个:

              <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Image") %>'
                    AutoAdjustImageControlSize="false" Width="90px" Height="110px"  Enabled="true"  AlternateText="pas d'image"/>

但我在 ImageButton 控件中没有任何 Datavalue 属性...

如何使用 ImageButton 来做到这一点? 提前致谢

【问题讨论】:

    标签: c# asp.net imagebutton imageurl


    【解决方案1】:

    您可以使用通用处理程序文件并将其称为 ImageUrl,例如:

    <asp:ImageButton ImageUrl='<%# String.Format("Image.ashx?id={0}", eval("ID")) %>' />
    

    在此处阅读有关如何执行此操作的更多信息:

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=129


    ImageButton 的事实没有任何区别。这是您想要从图像数据类型渲染图像的事实。我相信使用通用处理程序文件动态生成图像是最常见的方式。

    【讨论】:

    • 谢谢,是否有机会通过将我的 ImageButton 包含在具有 Click 属性的 LinkBut​​ton 中来使其工作? THX
    【解决方案2】:

    您可以使用处理程序从数据库或二进制格式创建图像,并且您可以从 imagebutton -> imageURL 调用此处理程序,它将在页面上显示图像。

    【讨论】:

      【解决方案3】:

      您可以提供一种将图像作为流返回的方法。您的网址可能是:

      http://www.yourwebsite.com/Application/Images/GetImage?name=myImageName&format=png

      在您的站点中,您将提供一个 GetImage 页面来查询数据库并将图像数据写入输出流(不要忘记设置 mime 类型)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-13
        • 2012-12-25
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多