ASP.NET - How to display multiple images?

Asked By shazi on 03-Jul-11 02:17 PM
Hai,

      in my page i am displaying images along with details .how can i display multiple images for one details
Peter Bromberg replied to shazi on 03-Jul-11 02:39 PM
We can assume that "details" must be some sort of GridView or DataList on the page, since you did not specify.

You can have as many Image tags in a row of a grid as you want, as long as each databinds to a different column in the data row.
Ashish Kapoor replied to shazi on 03-Jul-11 02:48 PM
drag and drop multiple image controls from the toolbox onto the webform and initialize each with urls of images at any event
Kirtan Patel replied to shazi on 03-Jul-11 03:05 PM
here is how you can do it 

 <asp:DataList ID="DataList1" runat="server">
 <ItemTemplate>
   <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageCol1") %>' />
   <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("ImageCol2") %>'/>
   <asp:Image ID="Image3" runat="server" ImageUrl='<%# Eval("ImageCol3") %>'/>
   <asp:Label ID="Label1" runat="server" Text='<%# Eval("SomeTextField") %>'>  </asp:Label>
 </ItemTemplate>
 </asp:DataList>
shazi replied to Kirtan Patel on 03-Jul-11 03:33 PM
Thanks
shazi replied to Kirtan Patel on 03-Jul-11 03:37 PM
now i am able to retrieve multiple images but its displaying da same details as number of images .
Kirtan Patel replied to shazi on 03-Jul-11 03:45 PM
not understood what do you mean by displaying da same details as number of images .?
Jitendra Faye replied to shazi on 04-Jul-11 12:21 AM

To show muliple images you can use GridView Control.

For that follow these steps-

Step1: Take one  GridView , and design it with Custom Column, Before that set it's AutoGeneratedColumns Property to False.

like this -

To show image in GridView, take one image control in itemTemplate of GridView.

<ItemTemplate>

<asp:Image ID="Image2" runat="server" ImageUrl='<%# "Handler1.ashx?EmpId=" + Eval("Empid")%>' />

</ItemTemplate>

Step2 ; After Designing GridView Take one Hander , Because this will be used for showing images

Use handler to show image-

//connect with database where you have stored images

public void ProcessRequest(HttpContext context)

{

SqlConnection cn = new SqlConnection("YOUR CONNECTION STRING");

cn.Open();

string empid = context.Request.QueryString["EmpID"].ToString();

SqlCommand cmd = new SqlCommand("select empimage from empimageTABLE where empid=" + empid, cn);

SqlDataReader dr = cmd.ExecuteReader();

dr.Read();

context.Response.BinaryWrite((byte[])dr["empimage"]);

dr.Close();

cn.Close();

}


try this code and let me know.



Devil Scorpio replied to shazi on 05-Jul-11 06:24 AM
Hi,

You can display multiple images through AJAX toolkit

You'll have to add the controls in the ToolBox. You can follow these few steps below:

  1. Download the compatible toolkit and unzip AJAX toolkit from here: http://www.asp.net/ajaxlibrary/act.ashx
  2. Right click on your Toolbar -> Add Tab -> Enter name of new tab
  3. Right click inside new tab -> Choose Items...
  4. In new window click on Browse... -> (navigate to the folder where you unzipped AJAX toolkit)/SampleWebSite/Bin/AjaxControlToolkit.dll -> Open -> then OK