The basic purpose of the AdRotator is to provide a graphic on a page that is chosen randomaly from the group of possible images. We can also say that every time the page is requested an image is selected at random and displayed. One use of the AdRotator is to show banner-style advertisements on a page. Th AdRotator stores its list of image files in an XML file. Later in this article I will tell you how to use this control in asp.net.
Free Download: AdRotator Control : Demo Project
Source Code of Web Page
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="168px" AutoPostBack="True"> <asp:ListItem>All</asp:ListItem> <asp:ListItem>Hosting</asp:ListItem> <asp:ListItem>Charting</asp:ListItem> <asp:ListItem>Products</asp:ListItem> </asp:DropDownList> <asp:AdRotator ID="AdRotator1"runat="server"DataSourceID="XmlDataSource1" Height="100px" Width="200px" /> <asp:XmlDataSource ID="XmlDataSource1"runat="server"DataFile="~/Ads.xml"> </asp:XmlDataSource>
</form> </body>
Aspx.cs Page Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string keyword = DropDownList1.SelectedItem.Text; if (keyword != "All") { AdRotator1.KeywordFilter = keyword; } else { AdRotator1.KeywordFilter = string.Empty; } AdRotator1.DataBind(); }
Ads.xml Code(XML File Code):
<?xml version="1.0" encoding="utf-8" ?> <Advertisements xmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File"> <Ad> <ImageUrl>~/images/dp.gif</ImageUrl> <NavigateUrl>http://www.dynamicpdf.com</NavigateUrl> <AlternateText>Dynamic PDF - Generate PDFs in .NET</AlternateText> <Impressions>10</Impressions> <Keyword>Products</Keyword> </Ad> <Ad> <ImageUrl>~/images/da.gif</ImageUrl> <NavigateUrl>http://www.discountasp.net</NavigateUrl> <AlternateText>ASP.NET Hosting</AlternateText> <Impressions>10</Impressions> <Keyword>Hosting</Keyword> </Ad> <Ad> <ImageUrl>~/images/dundas.jpg</ImageUrl> <NavigateUrl>http://www.dundas.com</NavigateUrl> <AlternateText>Dundas Software</AlternateText> <Impressions>10</Impressions> <Keyword>Charting</Keyword> </Ad>
</Advertisements>


[...] The basic purpose of the AdRotator is to provide a graphic on a page that is chosen randomaly from the group of possible images. We can also say that every time the page is requested an image is selected at random and displayed. One use of the AdRotator is to show banner-style advertisements on a page. Th AdRotator stores its list of image files in an XML file. Later in this article I will tell you how to use this control in asp.net. Read more on Hosting Asp [...]
This is the error i get in the xml file.
Warning 8 The element ‘Advertisements’ in namespace ‘http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File‘ has invalid child element ‘Ad’ in namespace ‘http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File'. List of possible elements expected: ‘Ad’. C:\Users\Onyebuchim\Documents\Visual Studio 2008\Projects\E-Register\Ads.xml 3 4 C:\…\E-Register\
A second error i get is: “An entry with the same key has already been entered”