Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用产品图像直接指向产品详细信息_C#_Asp.net_Image - Fatal编程技术网

C# 使用产品图像直接指向产品详细信息

C# 使用产品图像直接指向产品详细信息,c#,asp.net,image,C#,Asp.net,Image,我正在尝试使用我先前创建的图像控件,在单击图像时将图像定向到“产品详细信息”页面: ProductDetail.aspx?ProductId={0} ) 下面的代码只是我显示图像并将其绑定到图像控件中的方式。这是我的aspx.cs: protected string GetProductImgUrl(int productId) { var sqlText = "SELECT pProductImage FROM Products WHERE pProductId =

我正在尝试使用我先前创建的图像控件,在单击图像时将图像定向到“产品详细信息”页面:

ProductDetail.aspx?ProductId={0} )
下面的代码只是我显示图像并将其绑定到图像控件中的方式。这是我的aspx.cs:

protected string GetProductImgUrl(int productId)
    {
        var sqlText = "SELECT pProductImage FROM Products WHERE pProductId = " + productId.ToString();
        using (var mDB = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessConnection"].ConnectionString))
        {
            mDB.Open();
            var cmd = new OleDbCommand(sqlText, mDB);
            using (var rdr = cmd.ExecuteReader())
            {
                if (rdr.Read())
                {
                    return ResolveUrl((rdr["pProductImage"]).ToString());
                }
            }
        }
        return ResolveUrl("~/images/NotAvailable.png");     // Not available image
    }
这是我的分数:

 <div class="imagesfloat" >
     <img width="100" height="100" src='<%= GetProductImgUrl(3) %>' alt="" />
 </div>

“alt=”“/>
当我使用gridview控件时,逻辑是相同的,我从数据字段
ProductId
和URl格式字符串
ProductDetail.aspx?ProductId={0}


但是,在这种情况下,我没有使用GridView控件。

只需将图像标记包装在锚定标记中即可

 <div class="imagesfloat" >
     <a href="productdetails.aspx?productdetid=3">
        <img width="100" height="100" src='<%= GetProductImgUrl(3) %>' alt="" />
     </a>
 </div>

试试JS onClick和一个类似这样的小重定向函数

<div class="imagesfloat" >
         <img width="100" height="100" onclick='goToProductPage(3);' src='<%= GetProductImgUrl(3) %>' alt="" />
</div>

“alt=”“/>
和一个JS函数

<script type="text/javascript">
function goToProductPage(prodId){
    window.location = "ProductDetail.aspx?ProductId="+prodId;
}
</script>

函数goToProductPage(prodId){
window.location=“ProductDetail.aspx?ProductId=“+prodId;
}