Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can do like this......</p> <p>you have to add new generic handler -------Right click on solution Explorer and add new Generic Handler and name it “ImageHandler.ashx”</p> <p>NOTE : This is only sample example on how to load images from database and display in gridview</p> <p>this is the code in imagehandler.ashx</p> <pre><code>&lt;%@ WebHandler Language="C#" %&gt; using System; using System.Web; using System.IO; using System.Drawing.Imaging; using System.Collections.Generic; using System.Linq; public class ImageHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { HttpRequest req = context.Request; // string categoryID = "1"; string categoryID = req.QueryString["CategoryID"].ToString(); // Get information about the specified category NorthwindDataContext db = new NorthwindDataContext(); var category = from c in db.Categories where Convert.ToInt32(c.CategoryID) == Convert.ToInt32(categoryID) select c.Picture; int len = category.First().Length; // Output the binary data // But first we need to strip out the OLE header int OleHeaderLength = 78; int strippedImageLength = len - OleHeaderLength; byte[] imagdata = new byte[strippedImageLength]; Array.Copy(category.First().ToArray(), OleHeaderLength, imagdata, 0, strippedImageLength); if ((imagdata) != null) { MemoryStream m = new MemoryStream(imagdata); System.Drawing.Image image = System.Drawing.Image.FromStream(m); image.Save(context.Response.OutputStream, ImageFormat.Jpeg); } } public bool IsReusable { get { return false; } } } </code></pre> <p>and in Default.aspx page add new Gridview control and bind it using SQLDatasource control</p> <pre><code>&lt;div&gt; &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None"&gt; &lt;RowStyle BackColor="#EFF3FB" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" /&gt; &lt;asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" /&gt; &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /&gt; &lt;asp:TemplateField HeaderText="Picture" SortExpression="Picture"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("Picture") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Image ID="Image1" runat="server" ImageUrl='&lt;%#"ImageHandler.ashx?CategoryID="+ Eval("CategoryID") %&gt;'/&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt; &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt; &lt;EditRowStyle BackColor="#2461BF" /&gt; &lt;AlternatingRowStyle BackColor="White" /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:NorthwindConnectionString %&gt;" SelectCommand="SELECT * FROM [Categories]"&gt;&lt;/asp:SqlDataSource&gt; &lt;/div&gt; </code></pre> <p>I hope it will helps you......</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload