Dynamically binding image in dataview

  1. #1

    Dynamically binding image in dataview



    Hi
    In the Dataview example, you have bind the image in dataview which is within the folder and shown. how to bind image from database/blob to dataview. i want to bind the images dynamically. In the last post you mentioned refer speedstepmem4 for further. they have bind single image. i want to bind more images like in your dataview example but i need bind images from database. please help me for this send me full details about how to bind from database in dataview..

    Thanks in advance.

    I am looking forward for answer
  2. #2

    RE: Dynamically binding image in dataview

    Hi,

    What difference one image and many?
    For retrieving image from DB you need:

    1. Http Handler which retrieve image from DB by id and send back to the client. It can looks like:
    public void ProcessRequest(HttpContext context)
        {
          string id = context.Request.QueryString["id"];
          if (id == null || id.Length == 0)
            throw new ArgumentException("An 'id' query string value must be specified.");
    
          using (SqlConnection cn = new SqlConnection(_connectionstring))
          {
            SqlCommand cmd = new SqlCommand("SELECT ContentType, BinaryData FROM Resources WHERE ResourceId=@id", cn);
            cmd.Parameters.Add("@id", SqlDbType.VarChar, 50);
            cmd.Parameters["@type"].Value = id
            cn.Open();
            //CommandBehavior.SequentialAccess avoids loading the entire BLOB in-memory.
            SqlDataReader r = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
            if (r.Read())
            {
              context.Response.ContentType = r.GetString(0);
              byte[] buffer = new byte[ChunkSize];
              long idx = 0;
              long size = 0;
              //Write the BLOB chunk by chunk.
              while ((size = r.GetBytes(1, idx, buffer, 0, ChunkSize)) == ChunkSize)
              {
                context.Response.BinaryWrite(buffer);
                idx += ChunkSize;
              }
               //Write the last bytes.
               byte[] remaining = new byte[size];
               Array.Copy(buffer, 0, remaining, 0, size);
               context.Response.BinaryWrite(remaining);
            }
    
          }
        }
    2. You need define in DataView's Template image tag which will reference to that http handler
    <Template runat="server">
                                <tpl for=".">
                                    <div class="thumb-wrap" id="{name}">
                                        <div class="thumb"><img src="myImageHandler.ashx?id={imageID}" title="{name}">
    
                                        {shortName}
                                    
    
                                </tpl>
                                <div class="x-clear">
                                
                            </Template>     
    
    Hope this help
  3. #3

    RE: Dynamically binding image in dataview

    Hi Vladimir ,

    How to get selected Item in DataView, pls help me am Stuck ? I their any tutorial Site for Coolite ?

Similar Threads

  1. [CLOSED] Dataview add image during directmethod
    By Marcelo in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 23, 2012, 8:24 AM
  2. [CLOSED] Dynamically added Ext.Net.Image not converting '~/'
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 31, 2011, 7:28 AM
  3. dynamically added image and getOriginalSize()
    By bakardi in forum 1.x Help
    Replies: 1
    Last Post: Nov 15, 2010, 4:38 PM
  4. Add Image to grid dynamically
    By ajaybabu.maddinani in forum 1.x Help
    Replies: 0
    Last Post: Jun 29, 2010, 10:48 AM
  5. Blob field Image binding
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 10, 2009, 6:24 AM

Posting Permissions