title: Rendering bytes from sql server to an image control?
body: <p>Markup:</p>
  
  <pre><code>&lt;asp:ListView ID="lvGallery" runat="server" DataSourceID="SqlDataSource1"&gt;
      &lt;LayoutTemplate&gt;
          &lt;table runat="server" id="tableGallery"&gt;
              &lt;tr runat="server" id="itemPlaceHolder"&gt;&lt;/tr&gt;       
          &lt;/table&gt;       
      &lt;/LayoutTemplate&gt;
      &lt;ItemTemplate&gt;       
      &lt;tr&gt;
          &lt;td&gt;
              &lt;div class="box_img2"&gt;
                  &lt;div class="g_size"&gt;
                      &lt;a runat="server" id="linkImage"&gt;
                          &lt;img id="Image1" runat="server" src="MyImage.jpg" /&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;         
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
     &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;    
  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..."  ProviderName="System.Data.SqlClient"  SelectCommand="SELECT [Image] FROM [GalleryImages]"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>I have also added httphandlers section in web.config. But I don't get  the images in ListView control.</p>