2

我按照这个链接的教程Ajax Slide show extender

我的代码如下

<div>
    <table style="border:Solid 3px #D55500; width:400px; height:400px" cellpadding="0"  
           cellspacing="0">
        <tr style="background-color:#D55500">
            <td style=" height:10%; color:White; font-weight:bold; font-size:larger"  
                align="center">
                <asp:Label ID="lblTitle" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Image ID="imgslides" runat="server" Height="400px" Width="400px" />
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Label ID="lblimgdesc" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnPrevious" runat="server" Text="Prev" CssClass="button" />
                <asp:Button ID="btnPlay" runat="server" Text="Play" CssClass="button" />
                <asp:Button ID="btnNext" runat="server" Text="Next" CssClass="button" />
            </td>
        </tr>
    </table>
  <ajax:SlideShowExtender runat="server" AutoPlay="true" ImageTitleLabelID="lblTitle"  
   ImageDescriptionLabelID="lblimgdesc" Loop="true"
   NextButtonID="btnNext" PreviousButtonID="btnPrevious" PlayButtonID="btnPlay"   
   PlayButtonText="Play" StopButtonText="Stop"
   TargetControlID="imgslides" SlideShowServicePath="Slideshow.asmx"   
   SlideShowServiceMethod="GetSlides"></ajax:SlideShowExtender>

在我的网络服务中我有一个文件

[WebMethod]     
    public AjaxControlToolkit.Slide[] GetSlides()
    {
        string[] ImageNames = System.IO.Directory.GetFiles(Server.MapPath(@"C:\Users\Mayer\Documents\Visual Studio 2010\Projects\Project1\Project1\Images\"));
        AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[ImageNames.Length];
        for (int i = 0; i < ImageNames.Length; i++)
        {
            string[] file = ImageNames[i].Split('\\');
            photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
        }
        return photos;
    }

我有图像文件夹,但看不到幻灯片

请帮忙

4

1 回答 1

3

您应该将相对地址传递给Server.MapPath

它应该类似于:~\Project1\Project1\Images\而不是物理路径:
C:\Users\Mayer\Documents\Visual Studio 2010\Projects\Project1\Project1\Images\

MapPath 方法将指定的相对或虚拟路径映射到服务器上相应的物理目录。

来自文档: http: //msdn.microsoft.com/en-us/library/ms524632 (v=vs.90).aspx

于 2013-04-19T13:24:25.817 回答