Free Jobs
Reference




Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How to show Images in Datalist with each image posting back to different URL

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: madhuri22 Post Date: 16 Dec 2010 06:30

Introduction:
Many a times you may need to create a webpage with a group of Images
dynamically each pointing to different URL.In this post we will be doing
this.



Main Content:
It is a well known fact that ASP.NET data list control can create data
list.Here we will just replace data with images.

Considering PostBackUrl ,ImageFileUrl and ImageName stored in the database
we can get these values in the Dataset in our presentation layer.

The basic aim of this post is to explain how to bind the Images with
DataList control so the database part is omitted.

write the following code in the .cs file to bind the

public void GetImages()
{



DataSet dsImages = Bal.GetImages();
if (dsImages != null)
{
MyImageList.DataSource = dsImages;
MyImageList.DataBind();
}
}

Note it is assumed that there are at least three fields PostBackUrl ,ImageFileUrl and ImageName
in the dsImages DataSet.

<asp:DataList id="MyImageList" runat="Server" repeatdirection="Horizontal" RepeatColumns="10" > <ItemTemplate> <table runat="server" id = "ImageTable"> <tr> <td> <asp:Label runat="server" ID = "ImageID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem,"ImageID")%>' ></asp:Label> <asp:ImageButton ID="MyImage" runat="server" Width="50" Height="50" PostBackUrl='<%# "http://www.yourdomain.com/"+ Eval("PostBackUrl") %>' ImageUrl='<%# "http://www.yourdomain.com/images/" + Eval("ImageFileUrl") %>' ToolTip='<%# DataBinder.Eval(Container.DataItem,"ImageName")%>' AlternateText='<%# DataBinder.Eval(Container.DataItem,"ImageName") %>' /> </td> </tr> </table> </ItemTemplate> </asp:DataList>


Conclusion:
Note that you can change the repeatdirection and RepeatColumns properties of
DataList control to display the images as per your wish.



About Writer:
Hi ,I am .net Developer From Chennai


Writer's Link:

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)