Link to home
Start Free TrialLog in
Avatar of Robert Treadwell
Robert TreadwellFlag for United States of America

asked on

AdRotator with Datasource

I am using the ADRotator control with Datasource and I am getting the following error.

Exception Details: System.Web.HttpException: Only one of AdvertisementFile, DataSource, or DataSourceID properties can be set on AdRotator 'AdRotator1'.

Line 12:     Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 13:         AdRotator1.DataSource = FetchPicsFromDB()
Line 14:         AdRotator1.DataBind()
Line 15:     End Sub
Line 16:

The code below is what I have currently.  Can anyone help understand what the problem may be and how to solve it?  Side note I am using VWD 2010 & 4.0 .Net Framework, I don't know if this is causing a problem.
HTML:

<form id="form1" runat="server">
        <div class="bannerdiv">
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:IATDatabaseConnectionString %>" 
                SelectCommand="SELECT [ImgPath], [RedirectUrl], [AltText] FROM [PicBanner]"></asp:SqlDataSource>
            <asp:ScriptManager ID="ScriptManager1" runat="server"/>
            <asp:Timer ID="Timer1" Interval="2000" runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                </Triggers>
                <ContentTemplate>
                    <asp:AdRotator
                    id="AdRotator1"
                    runat="server" 
                    DataSourceID="SqlDataSource1"  
                    ImageUrlField="ImgPath" 
                    NavigateUrlField="RedirectUrl" 
                    AlternateTextField="AltText" 
                    Target="_blank"/>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>

Code behind:   

 Public Category As String
    Dim rowsAffected As Integer
    Public dt As DataTable = New DataTable()
    
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AdRotator1.DataSource = FetchPicsFromDB()
        AdRotator1.DataBind()
    End Sub

    Protected Function FetchPicsFromDB() As DataTable
        Dim myConnectionString As String
        Dim mQuery As String = "SELECT ImgPath, RedirectUrl, AltText FROM PicBanner"

        myConnectionString = "Data Source=Database Information"
        Dim da As New SqlDataAdapter(mQuery, myConnectionString)

        da.Fill(dt)
        FetchPicsFromDB = dt
    End Function

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        AdRotator1.DataSource = FetchPicsFromDB()
        AdRotator1.DataBind()
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial