?
Solved

AdRotator with Datasource

Posted on 2010-01-11
1
Medium Priority
?
1,096 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:Robert Treadwell
1 Comment
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 2000 total points
ID: 26286727
Hi,

In your markup you have already declaratively specified a datasource:

                    DataSourceID="SqlDataSource1"

Then you specify another datasource in the page_load, remove the declaratively specified datasource.

/Carl.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question