-1
Я не могу показать изображения из базы данных в gridview. Я могу их спасти. Когда я пытаюсь получить его, он не отображает ничего, кроме имени продукта.Невозможно отобразить изображение в GridView
Вот мой GridView.
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:ImageField DataImageUrlField = "ProductImagesID"
DataImageUrlFormatString = "../ImageHandler.ashx?ProductImagesID={0}"
ControlStyle-Width = "75" ControlStyle-Height = "75"
HeaderText = "Preview Image">
<ControlStyle Height="100px" Width="100px"></ControlStyle>
</asp:ImageField>
</Columns>
Handler Изображение:
public void ProcessRequest(HttpContext context)
{
Byte[] productImage;
if (context.Request.QueryString["ProductImageId"] != null)
{
int productImageId = Convert.ToInt32(context.Request.QueryString["ProductImageId"]);
productImage = ProductImageBL.GetImage(productImageId);
if (productImage != null)
{
context.Response.BinaryWrite(productImage);
context.Response.End();
}
}
}
ProductImageBL GetImage Метод:
public static Byte[] GetImage(int productImageId)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select ProductImage from ProductImages where ProductImageId = @ProductImageId";
cmd.Parameters.AddWithValue("@ProductImageId", SqlDbType.Int).Value = productImageId;
SqlDataReader dataReader = DbUtility.GetDataReader(cmd);
if (dataReader.HasRows)
{
dataReader.Read();
return (Byte[])dataReader[0];
}
else
{
return null;
}
}
Пожалуйста, помогите мне с этим кодом.
Спасибо заранее.
Пожалуйста, измените вопрос, чтобы включить разделы _relevant_ вашего кода. Это сообщество не относится к внешним ссылкам к коду, и ваш вопрос гораздо более вероятен для получения ответов, если вы предоставляете код напрямую. –