开发者

ListView Rendering image issue. [duplicate]

开发者 https://www.devze.com 2023-03-24 11:29 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Rendering bytes from sql server to an image control?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Rendering bytes from sql server to an image control?

<asp:ListView ID="lvGallery" runat="server" DataSourceID="SqlDataSource1">
 开发者_开发问答  <LayoutTemplate>
   <table runat="server" id="tableGallery">
   <tr runat="server" id="itemPlaceHolder">

   </tr>

   </table>

   </LayoutTemplate>
   <ItemTemplate>       
   <tr><td>
   <div class="box_img2">
            <div class="g_size">
                <a runat="server" id="linkImage"><img id="Image1" runat="server" src="MyImage.jpg" /></a>
            </div>         
   </div>
   </td></tr>
   </ItemTemplate>
   </asp:ListView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="Data Source=CHANDAN-PC;Initial Catalog=Metamorphism;User ID=sa;password=chandan;" 
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT [Image] FROM [GalleryImages]"></asp:SqlDataSource>


public void ProcessRequest(HttpContext context)
        {
            //write your handler implementation here.
            string username = Convert.ToString(context.Request.QueryString["username"]);
            if (username != null)
            {
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                byte[] arrContent;
                DataRow dr;
                string strSql;
                strSql = "Select Image from GalleryImages where username = '" + username + "'";
                da = new SqlDataAdapter(strSql, connection.ConnectionString);
                da.Fill(ds);
                dr = ds.Tables[0].Rows[0];
                arrContent = (byte[])dr["ImageFile"];
                context.Response.ContentType = "jpeg";
                context.Response.OutputStream.Write(arrContent, 0, arrContent.Length);
                context.Response.End();
            }
        }

I have added httphandlers tag in web.config.


I think you need to change this

     <div class="box_img2">
                <div class="g_size">
                    <a runat="server" id="linkImage">
<img id="Image1" runat="server" src='<%# Eval( HttpContext.Current.Request.QueryString["username"] ,"YourGenericHandler.ashx?username={0}") %>' /></a>
                </div>         
       </div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号