来自 SQL 数据库的图片未通过 jquery lightbox 在detailsView ImageField 和 asp:Image 控件(母版页)中显示
当我单击detailsView ImageField中显示的图片时,会弹出jquery lightbox,但不显示图片。它在灯箱中间显示一个红色的 x。下面代码中显示的 asp:Image 控件也会发生同样的情况。图片存储在 SQL 数据库 Image 数据类型中。使用母版页。
<asp:DetailsView ID="dvRoom" runat="server" AutoGenerateRows="False"
DataKeyNames="RoomID" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity"/>
<asp:BoundField DataField="Description" HeaderText="Description"/>
<asp:HyperLinkField HeaderText="Calendar URL" datatextfield="Name"
datanavigateurlfields="WebAddress" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" CssClass="lightbox"
ImageUrl='<%# Eval("RoomID", "~/DisplayImage.aspx?RoomID={0}") % >' />
</ItemTemplate>
<ControlStyle Height="75px" />
<ItemStyle Height="75px" />
</asp:TemplateField>
<asp:ImageField HeaderText = "Photo" ControlStyle-CssClass="lightbox"
AlternateText="no image found in database" DataImageUrlField="RoomID"
DataImageUrlFormatString="~/DisplayImage.aspx?RoomID={0}">
<ControlStyle Width="150px" />
</asp:ImageField>
</Fields>
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:DetailsView>
public partial class DisplayImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings
["ConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText= "SELECTfromRoomWithRoomID";
cmd.Connection = cn;
SqlParameter paraName = new SqlParameter("@RoomID", SqlDbType.Int);
paraName.Value = Request.QueryString["RoomID"].ToString();
cmd.Parameters.Add(paraName);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
try
{
if (dr.Read()) //check to see if image was found
{
//Response.ContentType = dr["fileType"].ToString();
Response.BinaryWrite((byte[])dr["Image"]);
}
}
catch (InvalidCastException iceE)
{
return;
}
cn.Close();
}
}
<asp:Content ID="Content4" ContentPlaceHolderID="Main" Runat="Server">
<script type="text/javascript">
$(document).ready(function () {
$(".lightbox").lightBox({
overlayBgColor: '#FFF',
overlayOpacity: 0.6,
imageLoading: 'Image/lightbox-ico-loading.gif',
imageBtnClose: 'Image/lightbox-btn-close.gif',
imageBtnPrev: 'Image/lightbox-btn-prev.gif',
imageBtnNext: 'Image/lightbox-btn-next.gif',
containerResizeSpeed: 350,
txtImage: 'Imagem'
});
});
</script>
</asp:Content>
when i click the picture that is displayed in the detailsView ImageField, the jquery lightbox pops up, but does not show the picture. it shows a red x in the middle of the lightbox. the same thing happens with the asp:Image control shown in the code below. The picture is stored in a SQL database Image datatype. Using master pages.
<asp:DetailsView ID="dvRoom" runat="server" AutoGenerateRows="False"
DataKeyNames="RoomID" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity"/>
<asp:BoundField DataField="Description" HeaderText="Description"/>
<asp:HyperLinkField HeaderText="Calendar URL" datatextfield="Name"
datanavigateurlfields="WebAddress" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" CssClass="lightbox"
ImageUrl='<%# Eval("RoomID", "~/DisplayImage.aspx?RoomID={0}") % >' />
</ItemTemplate>
<ControlStyle Height="75px" />
<ItemStyle Height="75px" />
</asp:TemplateField>
<asp:ImageField HeaderText = "Photo" ControlStyle-CssClass="lightbox"
AlternateText="no image found in database" DataImageUrlField="RoomID"
DataImageUrlFormatString="~/DisplayImage.aspx?RoomID={0}">
<ControlStyle Width="150px" />
</asp:ImageField>
</Fields>
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:DetailsView>
public partial class DisplayImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings
["ConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText= "SELECTfromRoomWithRoomID";
cmd.Connection = cn;
SqlParameter paraName = new SqlParameter("@RoomID", SqlDbType.Int);
paraName.Value = Request.QueryString["RoomID"].ToString();
cmd.Parameters.Add(paraName);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
try
{
if (dr.Read()) //check to see if image was found
{
//Response.ContentType = dr["fileType"].ToString();
Response.BinaryWrite((byte[])dr["Image"]);
}
}
catch (InvalidCastException iceE)
{
return;
}
cn.Close();
}
}
<asp:Content ID="Content4" ContentPlaceHolderID="Main" Runat="Server">
<script type="text/javascript">
$(document).ready(function () {
$(".lightbox").lightBox({
overlayBgColor: '#FFF',
overlayOpacity: 0.6,
imageLoading: 'Image/lightbox-ico-loading.gif',
imageBtnClose: 'Image/lightbox-btn-close.gif',
imageBtnPrev: 'Image/lightbox-btn-prev.gif',
imageBtnNext: 'Image/lightbox-btn-next.gif',
containerResizeSpeed: 350,
txtImage: 'Imagem'
});
});
</script>
</asp:Content>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要提供一个标头来解释 DisplayImage 的内容类型。
我经常只使用 image/gif 无论扩展名如何..浏览器通常会计算出来。
I think you need to provide a Header to explain the Content-type from DisplayImage.
I have often used just image/gif no matter the extension.. the browser usually figures it out.