Storing Advertisements in an XML File : AdRotator « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <form id="form1" runat="server">
    <div class="content">

    <asp:AdRotator
        id="AdRotator1"
        AdvertisementFile="~/App_Data/Data.xml"
        KeywordFilter="banner"
        CssClass="banner"
        Runat="server" />

    <br />

    <div class="box">
        <asp:AdRotator
            id="AdRotator2"
            AdvertisementFile="~/App_Data/Data.xml"
            KeywordFilter="box"
            Runat="server" />
        <br /><br />
        <asp:AdRotator
            id="AdRotator3"
            AdvertisementFile="~/App_Data/Data.xml"
            KeywordFilter="box"
            Runat="server" />
    </div>


    <br />Here is the body text in the page.
    <br />Here is the body text in the page.
    <br />Here is the body text in the page.
    <br />Here is the body text in the page.
    <br class="clear" />
    </div>
    </form>
</body>
</html>

File: Data.xml

<Advertisements>
  <Ad>
    <ImageUrl>http://www.java2s.com/style/logo.png</ImageUrl>
    <Width>300</Width>
    <Height>50</Height>
    <NavigateUrl>http://www.java2s.com</NavigateUrl>
    <AlternateText>Banner Advertisement 1</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>banner</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/Ads/BannerAd2.gif</ImageUrl>
    <Width>300</Width>
    <Height>50</Height>
    <NavigateUrl>http://www.java2s.com</NavigateUrl>
    <AlternateText>Banner Advertisement 2</AlternateText>
    <Impressions>25</Impressions>
    <Keyword>banner</Keyword>
  </Ad>
  <!-- Box Advertisements -->
  <Ad>
    <ImageUrl>http://www.java2s.com/style/logo.png</ImageUrl>
    <Width>150</Width>
    <Height>150</Height>
    <NavigateUrl>http://www.java2s.com</NavigateUrl>
    <AlternateText>Box Advertisement 1</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>box</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/Ads/BoxAd2.gif</ImageUrl>
    <Width>150</Width>
    <Height>150</Height>
    <NavigateUrl>http://www.java2s.com</NavigateUrl>
    <AlternateText>Box Advertisement 2</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>box</Keyword>
  </Ad>
</Advertisements>








3.28.AdRotator
3.28.1.AdRotator randomly display different advertisements in a page
3.28.2.AdRotator for displaying your ad (C#)
3.28.3.OnAdCreated event
3.28.4.Storing Advertisements in an XML File
3.28.5.Storing Advertisements in a Database Table
3.28.6.Using the AdRotator control as a banner ad