Groups > Asp .Net > ASP.NET Tips and tricks > Working dynamic slideshow fed by MS Access and with Web Service




Working dynamic slideshow fed by MS Access and with Web
Service

Working dynamic slideshow fed by MS Access and with Web Service
Fri, 4 Jan 2008 11:09:59 +0000
Hello all, I finally was able to complete my dynamic slideshow which is fed by
an Access database, and running through a Web Service. Also 

Round Corners were used. Since it took me quite some time to finish and also got
help from all around, I decided to post it also over here, to give the
opportunity to use it. I made an overview on what has been used and the coding
is included in here. Have fun with
it.-----------------------------------------------------------------------------
------------------------------------------------------------o                   
            My database is made with the following fields and field types
(database sits in App_Data)


Fieldname            Type                   Description
nummer               autonumbering      = name of the picture (example:  1000 
)
cat                     numeric field         = category of the picture
(example: 1301 = Amilcar, 1101 = Alfa)
naam                  text field               = name of the car
model                 text field               = model of the car o             
                  My photos are in the map Photos and the filenames are from 1
to 999999. They must have .jpg as extension for the
moment--------------------------------------------------------------------------
---------------------
In Default.aspx I call Slidepage.aspx by: slidepage.aspx?catid=1101  ( catid is
the category from fieldname cat )   
<formid="form1"runat="server">
    <div>
        <ahref="Slidepage.aspx?catid=1301">
       
<imgalt=""src="photos/car.jpg"width="20"/>
        </a>
    </div>
    </form>
--------------------------------------------------------------------------------
---------------<%@PageLanguage="VB"AutoEventWireup="false"
;CodeFile="Slidepage.aspx.vb"Inherits="Slidepage"%><!D
OCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.
dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
    <title>Slideshow Page</title>
</head>
<body>
<scriptrunat="server">
    </script>
    <formid="form1"runat="server">
    <div>
           
<ajaxToolkit:ToolkitScriptManagerID="ScriptManager1"runat="ser
ver"/>
        <br/>
            <divstyle="text-align:center">
            <asp:PanelID="Panel1" runat="server"
BackColor="silver" Height="420" Width="620" >
              <br/>
               
<asp:ImageID="Image1"runat="server"Height="380"
BackColor="Silver" Width="525px"/>
            </asp:panel>
                <br/>
                <br/>
                <asp:LabelID="Name"runat="server"
Text="Name and Model" />
                <br/>
                <br/>
               
<asp:ButtonID="PrevButton"runat="server"Text="Prev&q
uot;Font-Size="Larger"/>
               
<asp:ButtonID="PlayButton"runat="server"Text="Play&q
uot;Font-Size="Larger"/>
               
<asp:ButtonID="NextButton"runat="server"Text="Next&q
uot;Font-Size="Larger"/>
                               
<ajaxToolkit:SlideShowExtenderID="SlideShowExtender1"runat="se
rver"
                             TargetControlID="Image1"                 
           SlideShowServicePath="Slideservice.asmx"
                             SlideShowServiceMethod="Getslides"
                             AutoPlay="true"
                             ImageDescriptionLabelID="ImageLabel1"
                             NextButtonID="NextButton"
                             PlayButtonID="PlayButton"
                             PlayButtonText="Play"
                             StopButtonText="Stop"
                             PreviousButtonID="PrevButton"/>
            </div>
    </div>
    </form>
</body>
</html>
--------------------------------------------------------------------------------
---------------
The codebehind in Slidepage.aspx.vb is: 
Partial Class Slidepage
    Inherits System.Web.UI.Page
    ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
HandlesMe.Load
        SlideShowExtender1.ContextKey = Request.QueryString("catid")
    EndSub
EndClass------------------------------------------------------------------------
-----------------------
In Slidepage.aspx I call the Slideservice:  Slideservice.asmx containing the
following code:
--------------------------------------------------------------------------------
--------------- 
 
<%@ WebService Language="VB"
CodeBehind="~/App_Code/SlidesService.vb"
Class="SlidesService" %>

--------------------------------------------------------------------------------
---------------
In this page I call SlidesService.vb  (this file sits inside map App_Code )
--------------------------------------------------------------------------------
---------------Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb
Imports System.Web.UI.Page
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _PublicClass SlideService
    Inherits System.Web.Services.WebService    
    <WebMethod()> _
    PublicFunction GetSlides(ByVal contextKey AsString) As
AjaxControlToolkit.Slide()
        Dim strconn AsString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|Vancouver.mdb"
        Dim cn AsNew OleDbConnection(strconn)
        Dim SQLStr AsString
        SQLStr = "SELECT nummer, naam, model FROM Autos WHERE ((Autos.cat)
= @catid)"
        Try
            cn.Open()
            Dim cmd AsNew OleDbCommand(SQLStr, cn)

            Dim sCatid As String = "" & contextKey
            ' If needed give a default value to sCatId (for example: 1101)
            If sCatid.Trim().Length = 0 Then sCatid = 1101
            cmd.Parameters.AddWithValue("@catid", sCatid)

            Dim thisReader As OleDbDataReader = cmd.ExecuteReader()

            Dim photoCounter AsInteger
            While (thisReader.Read())
                photoCounter = thisReader.GetInt32(0)
            EndWhile

            If (photoCounter > 0) Then
                Dim MySlides(photoCounter) As AjaxControlToolkit.Slide
                Dim photoLookupCmd AsNew OleDbCommand(SQLStr, cn)
                photoLookupCmd.Parameters.AddWithValue("@catid",
sCatid)

                thisReader = photoLookupCmd.ExecuteReader()

                Dim i AsInteger
                For i = 0 To photoCounter
                    thisReader.Read()
                    Dim number AsString = thisReader.GetInt32(0)
                    Dim name AsString = ("thisReader.GetString(1)" +
"thisReader.GetString(2)")
                    MySlides(i) = New
AjaxControlToolkit.Slide(("photos\" + number + ".jpg"),
name, "")
                Next
                thisReader.Close()
                Return MySlides
            Else
                Dim MySlides(0) As AjaxControlToolkit.Slide
                MySlides(0) = New
AjaxControlToolkit.Slide("photos\nopicture.jpg", "",
"")
                Return MySlides
            EndIf
        Catch x As Exception
        Finally
            cn.Close()
        EndTry
    EndFunction 
EndClass

 

These are all the pages you need. Hope that it works at your sites My last
thansk are for those who have helped my in the past weeks.
Post Reply
about | contact