如何在新窗口中显示图像 [英] How to display an image in a new window

查看:128
本文介绍了如何在新窗口中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后续问题<一href=\"http://stackoverflow.com/questions/4097438/how-to-display-an-image-based-on-selectedvalue-in-a-gridview\">How显示在GridView基于SelectedValue的图像?

我真的很想做的是,这样的被点击时,在一个新的浏览器窗口中会显示一个新的页面上的图像有我的GridView控件一个ViewImage按钮。我会怎么做呢?我想也许我需要创建一个

What I would really like to do is have a ViewImage button on my GridView control so that when that is clicked, the image is displayed on a new page in a new browser window. How would I do that? I'm thinking perhaps do I need to create a

<asp:ButtonField>

我如何处理点击我怎么去diplay在新的浏览器窗口中的新形式?

How do I handle the click and how do I get the image to diplay on a new form in a new web browser window?

非常感谢您寻找。

推荐答案

您可以使用TemplateColumn中,在TemplateColumn中,你可以定义你把JavaScript函数打开新窗口的按钮。



例如:

You can use TemplateColumn, in that TemplateColumn you can define a button where you put javascript function to open new window.

Example:

<asp:TemplateField>
    <ItemTemplate>
        <input type="button" onclick="javascript:ShowImageInNewPage('PageToShowImage.aspx?tradeId=<%# Eval("TradeId") %>');" />
    </ItemTemplate>
</asp:TemplateField>

在ShowImageInNewPage功能声明弹出与所选图像的URL /在新窗口打开自定义函数。

The "ShowImageInNewPage" function is a custom function you declare to popup/open new window with the selected image url.

在PageToShowImage.aspx,声明img标签:

In PageToShowImage.aspx, declare an img tag:

<asp:Image ID="imgBlah" runat="server" />

在code背后PageToShowImage.aspx的:

In code behind of PageToShowImage.aspx:

protected void Page_Load(object sender, EventArgs e)
{
    // this is querystring from GridView page
    if(Request.QueryString["tradeId"] != null)
    {
        imgBlah.Src = "GetImage.aspx?entityId=" + tradeId + "&entityType=T";
    }
    else
    {
        imgBlah.Src = "~/images/no-image.jpg"; // set no image
    }
}

心连心

这篇关于如何在新窗口中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆