【问题标题】:Click image in datalist单击数据列表中的图像
【发布时间】:2013-12-11 02:40:09
【问题描述】:

我在数据列表中有从数据库获取的图像。我希望能够点击一张图片,然后将我带到一个新页面,该页面将显示该图片并显示有关图片的信息。

<asp:HyperLink ID="hlnk" NavigateUrl='<%# string.Format("ViewProductDetail.aspx?Image={0}", Eval("Picture")) %>' runat="server">

        &nbsp;<asp:Image ID="Image1" runat="server" Height="127px" 
                ImageUrl='<%# Bind("Picture", "~/Image/{0}") %>' Width="129px" />

                </asp:HyperLink>

                <br />
        <asp:Label ID="ProductNameLabel" runat="server" 
            Text='<%# Eval("ProductName") %>' />
        <br />
        <asp:Label ID="PriceLabel" runat="server" 
            Text='<%# Eval("Price","{0:C}") %>' />

那么我必须为 ViewProductDetail.aspx 编写什么代码来检索我单击的图像的信息?

【问题讨论】:

  • ViewProductDetail.aspx 页面中有什么代码?你试过什么?另外,我认为 ASP.NET 将是一个比“图像”更有用的标记,至少添加 ASP.NET 标记。
  • er 目前是空的 >

标签: asp.net image datalist


【解决方案1】:

试试这个 根据这个在查询字符串中添加 ProdcutId

<asp:HyperLink ID="hlnk" NavigateUrl='<%# string.Format("ViewProductDetail.aspx?ProductId={0}", Eval("productid")) %>' runat="server">

    &nbsp;<asp:Image ID="Image1" runat="server" Height="127px" 
            ImageUrl='<%# Bind("Picture", "~/Image/{0}") %>' Width="129px" />

   </asp:HyperLink>

在 ViewProductDetail.aspx 页面加载事件中从查询字符串中获取 ProductId 值

if(Request.Querystring["ProductId"] !=null && Request.Querystring["ProductId"] !="")
{
  //get product details from product id and show on page
}

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    相关资源
    最近更新 更多