Hi ashish007,
Check this example. Now please take its reference and correct your code.
HTML
<div id="dvImage" style="height: 308px; width: 410px"></div>
JavaScript
C#
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var images = '<%=this.Images%>'.split(",");
$(function () {
var i = 0;
$("#dvImage").css("background-image", "url(" + images[i] + ")");
$("#dvImage").css("background-repeat", "no-repeat");
setInterval(function () {
i++;
if (i == images.length) {
i = 0;
}
$("#dvImage").fadeOut("slow", function () {
$(this).css("background-image", "url(" + images[i] + ")");
$(this).css("background-repeat", "no-repeat");
$(this).fadeIn("slow");
});
}, 2000);
});
</script>
VB.Net
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var images = '<%=Me.Images%>'.split(",");
$(function () {
var i = 0;
$("#dvImage").css("background-image", "url(" + images[i] + ")");
$("#dvImage").css("background-repeat", "no-repeat");
setInterval(function () {
i++;
if (i == images.length) {
i = 0;
}
$("#dvImage").fadeOut("slow", function () {
$(this).css("background-image", "url(" + images[i] + ")");
$(this).css("background-repeat", "no-repeat");
$(this).fadeIn("slow");
});
}, 2000);
});
</script>
Code
C#
protected string Images { get; set; }
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("Path")
});
dt.Rows.Add("Images/Chrysanthemum.jpg");
dt.Rows.Add("Images/Desert.jpg");
dt.Rows.Add("Images/Hydrangeas.jpg");
dt.Rows.Add("Images/Jellyfish.jpg");
dt.Rows.Add("Images/Koala.jpg");
dt.Rows.Add("Images/Lighthouse.jpg");
dt.Rows.Add("Images/Penguins.jpg");
dt.Rows.Add("Images/Tulips.jpg");
for (int i = 0; i < dt.Rows.Count; i++)
{
files.Add(dt.Rows[i]["Path"].ToString());
}
Images = string.Join(",", files.ToArray());
}
}
VB.Net
Protected Property Images As String
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("Path")})
dt.Rows.Add("Images/Chrysanthemum.jpg")
dt.Rows.Add("Images/Desert.jpg")
dt.Rows.Add("Images/Hydrangeas.jpg")
dt.Rows.Add("Images/Jellyfish.jpg")
dt.Rows.Add("Images/Koala.jpg")
dt.Rows.Add("Images/Lighthouse.jpg")
dt.Rows.Add("Images/Penguins.jpg")
dt.Rows.Add("Images/Tulips.jpg")
For i As Integer = 0 To dt.Rows.Count - 1
files.Add(dt.Rows(i)("Path").ToString())
Next
Images = String.Join(",", files.ToArray())
End If
End Sub
Screenshot