Internet Explorer 6.0IEIIS 6.0VBScriptIISVisual Studio 2005.NET 2.0XMLAjaxHTML中级开发Visual StudioJavascriptWindows.NET
使用 Ajax Toolkit 动态图像幻灯片






2.17/5 (3投票s)
2007年9月6日

69506

1123
本文展示了如何以幻灯片形式动态显示图像。
引言
最近,我一直在尝试使用 Ajax Toolkit 的各种功能。我尝试了幻灯片概念,并且效果很好,但是该代码需要硬编码图像路径,所以我想如果我想动态显示特定文件夹中的所有文件会怎么样?我为此工作并完成了它。我在这里展示它,希望对某人有用。
背景
要使用此代码,您应该安装 Ajax Toolkit。 此示例使用 Ajax Toolkit
使用代码
//With in the form beginning & closing tags place the following code<div> <script runat="server" type="text/VB"> <System.Web.Services.WebMethod()> _ <System.Web.Script.Services.ScriptMethod()> _ Public Shared Function GetSlides() As AjaxControlToolkit.Slide()Dim ObjUIPage As New System.web.ui.page Dim i As Integer = 0 Dim j As Integer//The below line specifies the Directory to be used.Here the images are in images folder of my applicationDim DirInfo As New System.IO.DirectoryInfo(ObjUIPage.Server.MapPath("") & "\images") Dim subDirs As System.IO.DirectoryInfo() = DirInfo.GetDirectories()//The below line gets the list of files in the directory specified aboveDim Files As System.IO.FileInfo() = DirInfo.GetFiles()//The below line gives the file count, which is useful to specify the size of arrayj = Files.Length Dim mySlides() As Slide = New AjaxControlToolkit.Slide(j) {} Dim di As System.IO.FileInfo//This loop continues upto the last file in the directoryFor Each di In Files mySlides(i) = New AjaxControlToolkit.Slide(di.FullName, di.Name, di.Name.Substring(0,( di.Name.IndexOf(".")))Next diReturn mySlides i = i + 1 Next di//this line sends the dynamically added details as AjaxControlToolkit.SlideEnd Function </script><asp:ScriptManager runat="server" ID="SideShow" ></asp:ScriptManager> <asp:Label runat="Server" ID="imageTitle" CssClass="slideTitle"/><br /> <asp:Image ID="Image1" runat="server" Height="300" Style="border: 1px solid black;width:auto" ImageUrl="images/Blue hills.jpg" AlternateText="Blue Hills image" /> <asp:Label runat="server" ID="imageDescription" CssClass="slideDescription"> </asp:Label><br /><br /> <asp:Button runat="Server" ID="prevButton" Text="Prev" Font-Size="Larger" /> <asp:Button runat="Server" ID="playButton" Text="Play" Font-Size="Larger" /> <asp:Button runat="Server" ID="nextButton" Text="Next" Font-Size="Larger" /> <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="Image1" AutoPlay="true" ImageTitleLabelID="imageTitle" SlideShowServiceMethod = "GetSlides" ImageDescriptionLabelID="imageDescription" NextButtonID="nextButton" PlayButtonText="Play" StopButtonText="Stop" PreviousButtonID="prevButton" PlayButtonID="playButton" Loop="true" /> </div> //