在asp.net中幻灯片放映扩展器的麻烦

时间:2013-10-15 04:15:28

标签: c# asp.net ajax

我在asp.net中使用数据库中的图像进行幻灯片放映。但事情没有成功..
这是我的aspx页面代码:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:Image ID="Image1" runat="server"/>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Prev" />
<asp:Button ID="Button2" runat="server" Text="Play" />
<asp:Button ID="Button3" runat="server" Text="Next" />
<asp:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="Image1" Loop="True" ImageTitleLabelID="Label1" SlideShowServiceMethod="getslides" NextButtonID="Button3" PlayButtonID="1" PlayButtonText="Play" PreviousButtonID="Button1"></asp:SlideShowExtender>

.cs代码是:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] getslides()
{
int i=0;
AjaxControlToolkit.Slide[] imgSlide= new AjaxControlToolkit.Slide[5];
string str1 = ConfigurationManager.ConnectionStrings["database1"].ConnectionString;
    SqlConnection cn = new SqlConnection(str1);
    SqlCommand cmd = new SqlCommand("select * from Image where uid=@uid", cn);
    cmd.Parameters.AddWithValue("@uid", Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));
    SqlDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        imgSlide[i] = new AjaxControlToolkit.Slide("~/Handler2.ashx?id=" + dr["ImageId"].ToString(), dr["Descr"].ToString(), " ");
        i++;
    }

    return (imgSlide);
}

处理程序代码为:

 public void ProcessRequest (HttpContext context) {
    string str1 = ConfigurationManager.ConnectionStrings["database1"].ConnectionString;
    SqlConnection con = new SqlConnection(str1);
    con.Open();
    SqlCommand cmd2 = new SqlCommand("select * from  Image where ImageId=@id", con);
    cmd2.Parameters.AddWithValue("@id",Convert.ToInt32(context.Request.QueryString["id"]));
    SqlDataReader dr = cmd2.ExecuteReader();
    dr.Read();
    context.Response.BinaryWrite((byte[])dr["image"]);

    dr.Close();
    con.Close();

}

现在问题是没有显示图像,编译器也没有显示任何错误。

1 个答案:

答案 0 :(得分:0)

我认为它会对您有所帮助,请参阅此链接 http://www.aspdotnet-suresh.com/2011/03/ajax-slideshowextender-control-sample.html