Add images to slideshow using xml file Part 137

  • دعنا نشارك هذا :
ترتيب الدرس : 137
المدة : 00:17:45
التحكم :
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/07/add-images-to-slideshow-using-xml-file.html

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1

Slides
http://csharp-video-tutorials.blogspot.com/2013/08/part-137-add-images-to-slideshow-using.html

All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html

All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html

ASP.NET Playlist
https://www.youtube.com/playlist?listPL4cyC4G0M1RQcB4IYS_zwkyBwMyx5AnDM

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

There are 2 problems with the image slideshow, that we have built in Parts 134, 135, & 136.If we want to add a new image to the slide show,
1. We will have to modify the application code
2. The new image has to be named in a specific way. Since we already have 8 images, the next image has to be named 9.jpg.

There are two ways to fix the above 2 issues.
1. Using an XML file
2. Using a database table

In this video, we will discuss using an XML file and in our next video, we will discuss using a database table.

Step 1: At the moment the images in "Images" folder have the following names
1.jpg
2.jpg
3.jpg
etc.

Delete all these 8 images. Now copy the images with their original names from "C:\Users\Public\Pictures\Sample Pictures".

Step 2: Right click on the project name in solution explorer, and add "Data" folder. Add "ImageData.xml" file. Copy and paste the XML from my bog.

Deafult.aspx code:
[%@ Page Title"Home Page" Language"C#" MasterPageFile"~/Site.master" AutoEventWireup"true"
CodeBehind"Default.aspx.cs" Inherits"ImageSlideShow._Default" %]
[asp:Content ID"HeaderContent" runat"server" ContentPlaceHolderID"HeadContent"]
[/asp:Content]
[asp:Content ID"BodyContent" runat"server" ContentPlaceHolderID"MainContent"]
[asp:ScriptManager ID"ScriptManager1" runat"server"]
[/asp:ScriptManager]
[asp:UpdatePanel ID"UpdatePanel1" runat"server"]
[ContentTemplate]
[asp:Timer ID"Timer1" runat"server" Interval"1000" OnTick"Timer1_Tick"]
[/asp:Timer]
[asp:Image ID"Image1" Height"200px" Width"200px" runat"server" /]
[br /]
[br /]
Name: [asp:Label ID"lblImageName" runat"server"][/asp:Label]
[br /]
Order: [asp:Label ID"lblImageOrder" runat"server"][/asp:Label]
[br /]
[br /]
[asp:Button ID"Button1" runat"server" Text"Stop Slideshow"
onclick"Button1_Click" /]
[/ContentTemplate]
[/asp:UpdatePanel]
[/asp:Content]

Default.aspx.cs code

namespace ImageSlideShow
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadImageData();
}
}

private void LoadImageData()
{
DataSet dsnew DataSet();
ds.ReadXml(Server.MapPath("~/Data/ImageData.xml"));
ViewState["ImageData"]ds;

ViewState["ImageDisplayed"]1;
DataRow imageDataRowds.Tables["image"].Select().FirstOrDefault(x ] x["order"].ToString()"1");
Image1.ImageUrl"~/Images/" + imageDataRow["name"].ToString();
lblImageName.TextimageDataRow["name"].ToString();
lblImageOrder.TextimageDataRow["order"].ToString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
int i(int)ViewState["ImageDisplayed"];
ii + 1;
ViewState["ImageDisplayed"]i;

DataRow imageDataRow((DataSet)ViewState["ImageData"]).Tables["image"].Select().FirstOrDefault(x ] x["order"].ToString()i.ToString());
if (imageDataRow ! null)
{
Image1.ImageUrl"~/Images/" + imageDataRow["name"].ToString();
lblImageName.TextimageDataRow["name"].ToString();
lblImageOrder.TextimageDataRow["order"].ToString();
}
else
{
LoadImageData();
}
}

protected void Button1_Click(object sender, EventArgs e)
{
if (Timer1.Enabled)
{
Timer1.Enabledfalse;
Button1.Text"Start Slideshow";
}
else
{
Timer1.Enabledtrue;
Button1.Text"Stop Slideshow";
}
}
}
}

سيتم تفعيل التعليقات قريبا

y
Sep 23, 2020 07:32:26
youtube