62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;
public partial class PlayPhoto : System.Web.UI.Page
{
private int categoryID = -1;
protected void Page_Load(object sender, EventArgs e)
{
//获取当前分类的值
if (Request.Params["CategoryID"] != null)
{
categoryID = Int32.Parse(Request.Params["CategoryID"].ToString());
}
if(categoryID > 0)
{
//设置播放照片控件的属性
ssePhoto.AutoPlay = true;
ssePhoto.UseContextKey = true;
ssePhoto.ContextKey = categoryID.ToString();
return;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PlayPhoto.aspx.cs" Inherits="PlayPhoto" StylesheetTheme="ASPNETAjaxWeb" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>播放照片</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="upForm" runat="server">
<ContentTemplate>
<table border="0" cellpadding="5" cellspacing="0" class="Table">
<tr>
<td align="center"><asp:Image ID="imgShow" Height="400" runat="server" /></td>
</tr>
<tr>
<td align="center"><asp:Label ID="lbShow" runat="server" CssClass="Title" ></asp:Label></td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnPrev" runat="server" Text="上一张" SkinID="btnSkin" Width="80px" />
<asp:Button ID="btnPlay" runat="server" Text="开始" SkinID="btnSkin" Width="80px" />
<asp:Button ID="btnNext" runat="server" Text="下一张" SkinID="btnSkin" Width="80px" />
</td>
</tr>
</table>
<cc1:SlideShowExtender ID="ssePhoto" UseContextKey="true" runat="server" TargetControlID="imgShow" AutoPlay="true" ImageDescriptionLabelID="lbShow" Loop="true" NextButtonID="btnNext" PreviousButtonID="btnPrev" PlayButtonID="btnPlay" PlayInterval="3000" PlayButtonText="开始" StopButtonText="停止" SlideShowServicePath="AjaxService.asmx" SlideShowServiceMethod="GetPhotoes">
</cc1:SlideShowExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.Slide[] GetPhotoes(string contextKey)
{ ///检测参数是否为空
if (string.IsNullOrEmpty(contextKey) == true) return null;
///获取参数的值,并转换为分类的ID值
int categoryID = -1;
if (Int32.TryParse(contextKey, out categoryID) == false)
{
return null;
}
///根据分类ID获取其照片
Album album = new Album();
DataSet ds = album.GetPhotoByCategory(categoryID);
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
///创建被播放照片的数组
Slide[] photoes = new Slide[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ ///创建一张照片的数组
Slide photo = new Slide();
photo.Name = photo.Description = ds.Tables[0].Rows[i]["Title"].ToString();
photo.ImagePath = ds.Tables[0].Rows[i]["Url"].ToString();
photoes[i] = photo;
}
return photoes;
}
//获取总页码数量
if (ViewState[AjaxEBusinessSystem.TOTALPAGEINDEX] != null)
{
TotalPageIndex = Int32.Parse(ViewState[AjaxEBusinessSystem.TOTALPAGEINDEX].ToString());
}
DataSet ds = album.GetPhotoByCategory(categoryID);
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
///创建被播放照片的数组
Slide[] photoes = new slide[PicCount];
for (i = 0; i < PicCount; i++)
{
Slide photo = new Slide();
photo.Name = photo.Description = ds.Tables[0].Rows[i]["Title"].ToString();
photo.ImagePath = ds.Tables[0].Rows[i]["Url"].ToString();
photoes[i] = photo;
}
return photoes;