C# ASP.NET-单击图像应重定向到具有图像url的特定页面

C# ASP.NET-单击图像应重定向到具有图像url的特定页面,c#,asp.net,C#,Asp.net,我基本上是为我的大学项目制作一个网站,基本上是一个摄影和墙纸网站 我已将图像保存在文件夹(名为ImageStorage)中,我正在通过图像链接从数据库检索图像 我在我的页面(image viewer.aspx)中使用了datalist,将我的所有图像显示为imagebutton。我基本上想要的是,当用户单击一个图像时,它会重定向到另一个页面(image detail.aspx),并发送该图像的url或id,以便我可以使用它在(image detail.aspx)页面上显示该图像 以下是我的ima

我基本上是为我的大学项目制作一个网站,基本上是一个摄影和墙纸网站 我已将图像保存在文件夹(名为ImageStorage)中,我正在通过图像链接从数据库检索图像 我在我的页面(image viewer.aspx)中使用了datalist,将我的所有图像显示为imagebutton。我基本上想要的是,当用户单击一个图像时,它会重定向到另一个页面(image detail.aspx),并发送该图像的url或id,以便我可以使用它在(image detail.aspx)页面上显示该图像

以下是我的image_viewer.aspx代码:

<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" CellPadding="15" CellSpacing="10" DataSourceID="SqlDataSource1" GridLines="Both" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" RepeatColumns="3" RepeatDirection="Horizontal" style="margin-left: 0px" >
<ItemTemplate>
<br />
<asp:ImageButton ID="Image1"  style="width:335px ;height:210px" runat="server" ImageUrl='<%# Eval("ImagePath") %>' CommandName="imgClick"/>
</ItemTemplate>
</asp:DataList>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:photo_stock_viewConnectionString %>" SelectCommand="SELECT * FROM [ImageInfo1]"></asp:SqlDataSource>
<br />
</div>
</form>




image_detail.aspx中显示图像的HTML代码:

<img class="img-fluid mt-4" src="ImageStorage/image-detail.jpg"/>

您需要代码隐藏来处理图像单击事件

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "imgClick")
    {
       ImageButton btn = e.CommandSource as ImageButton;
       //Do what you need to do here
       string imgUrl = btn.ImageUrl;
       Response.Redirect(imgUrl,true);
}
如果您需要设置更多信息,比如imageID,您还可以使用CommandArgument作为参数,在html中设置并从代码隐藏中获取它
这是URL

这将如何将我带到另一个页面/您可以轻松地使用Response.Redirect(URL,true);好的,谢谢,它起作用了。现在,我如何将img路径移动到新页面(image detail.aspx)并在其中显示此图像,我将非常感谢!!我用它来移动到其他页面而不是ImageButton现在如何将img路径移动到新页面(image detail.aspx)并在ITX中显示此图像您可以使用它