简体   繁体   中英

Trouble with slide show extender in asp.net

I am using images in database for slide show in asp.net. but things are not working out..
Here is my aspx page code:

<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 code is:

[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);
}

Handler code is:

 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();

}

Now the problem is that no image is being displayed also the compiler does not show any errors.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM