来自 SQL 数据库的图片未通过 jquery lightbox 在detailsView ImageField 和 asp:Image 控件(母版页)中显示

发布于 2024-09-08 12:49:55 字数 3576 浏览 5 评论 0原文

当我单击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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-09-15 12:49:55

我认为您需要提供一个标头来解释 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文