Hi ashish007,
Check this example. Bind the ul using Repeater control from database.
HTML
<form id="form1" runat="server">
<style type="text/css">
.slides {
position: relative;
height: 150px;
padding: 0px;
margin: 0px;
list-style-type: none;
}
.slide {
position: absolute;
left: 0px;
top: 0px;
width: 150px;
height: 150px;
opacity: 0;
z-index: 1;
cursor: pointer;
border: 1px solid #0090CB;
-webkit-transition: opacity 1s;
-moz-transition: opacity 1s;
-o-transition: opacity 1s;
transition: opacity 1s;
}
.showing {
opacity: 1;
z-index: 2;
}
</style>
<ul id="slides" class="slides">
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<li class="slide">
<img src='<%# Eval("Path") %>' alt='<%# Eval("Name") %>' width="150" height="150" />
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function () {
var slides = $('[id*=slides] .slide');
$(slides).eq(0).addClass("showing");
var pauseButton = $('.slide');
var currentSlide = 0;
var playing = true;
var slideInterval = setInterval(nextSlide, 1000);
function nextSlide() {
slides[currentSlide].className = 'slide';
currentSlide = (currentSlide + 1) % slides.length;
slides[currentSlide].className = 'slide showing';
}
$(pauseButton).on('hover', function () {
if (playing) {
playing = false;
clearInterval(slideInterval);
} else {
playing = true;
slideInterval = setInterval(nextSlide, 1000);
}
});
});
</script>
</form>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<string> files = new List<string>();
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[]
{
new System.Data.DataColumn("Name"),
new System.Data.DataColumn("Path")
});
dt.Rows.Add("Chrysanthemum", "Images/Chrysanthemum.jpg");
dt.Rows.Add("Desert", "Images/Desert.jpg");
dt.Rows.Add("Hydrangeas", "Images/Hydrangeas.jpg");
dt.Rows.Add("Jellyfish", "Images/Jellyfish.jpg");
dt.Rows.Add("Koala", "Images/Koala.jpg");
dt.Rows.Add("Lighthouse", "Images/Lighthouse.jpg");
dt.Rows.Add("Penguins", "Images/Penguins.jpg");
dt.Rows.Add("Tulips", "Images/Tulips.jpg");
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim files As List(Of String) = New List(Of String)()
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn() {
New Data.DataColumn("Name"),
New Data.DataColumn("Path")})
dt.Rows.Add("Chrysanthemum", "Images/Chrysanthemum.jpg")
dt.Rows.Add("Desert", "Images/Desert.jpg")
dt.Rows.Add("Hydrangeas", "Images/Hydrangeas.jpg")
dt.Rows.Add("Jellyfish", "Images/Jellyfish.jpg")
dt.Rows.Add("Koala", "Images/Koala.jpg")
dt.Rows.Add("Lighthouse", "Images/Lighthouse.jpg")
dt.Rows.Add("Penguins", "Images/Penguins.jpg")
dt.Rows.Add("Tulips", "Images/Tulips.jpg")
Repeater1.DataSource = dt
Repeater1.DataBind()
End If
End Sub
Screenshot