Introduction:
AdRotator is used to display different advertisement
randomly in page. You can store the advertisement either in the XML file or stored in the
DataBase. Here I have used XML file to display the advertisement.
AdRotator.aspx:-
<!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">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="AspMaterials Blog"></asp:Label><br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/AdRotatorXMLFile.xml"></asp:XmlDataSource>
</div>
</form>
</body>
</html>
AdRotatorXMlFile.xml:-
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>image/google.jpg</ImageUrl>
<NavigatorUrl>http://wwww.google.com</NavigatorUrl>
<AlternateText>Google</AlternateText>
<Impressions>90</Impressions>
<Keyword>Search</Keyword>
</Ad>
<Ad>
<ImageUrl>image/msn.jpg</ImageUrl>
<NavigatorUrl>http://www.msn.com</NavigatorUrl>
<AlternateText>MSN</AlternateText>
<Impressions>80</Impressions>
<Keyword>MSN</Keyword>
</Ad>
<Ad>
<ImageUrl>image/Microsoft.jpg</ImageUrl>
<NavigatorUrl>http://www.microsoft.com</NavigatorUrl>
<AlternateText>Microsoft</AlternateText>
<Impressions>70</Impressions>
<Keyword>Read</Keyword>
</Ad>
<Ad>
<ImageUrl>image/AspMaterials.jpg</ImageUrl>
<NavigatorUrl>http://www.aspmaterials.blogspot.com</NavigatorUrl>
<AlternateText>Asp Materials</AlternateText>
<Impressions>90</Impressions>
<Keyword>Read</Keyword>
</Ad>
<Ad>
<ImageUrl>image/yahoo.jpg</ImageUrl>
<NavigatorUrl>http://www.yahoo.com</NavigatorUrl>
<AlternateText>Yahoo</AlternateText>
<Impressions>80</Impressions>
<Keyword>Search</Keyword>
</Ad>
</Advertisements>
Here image is folder name in which image has put. If you
want to put in main directory then just remove folder name with forward slash means write only image name
with extension.
Run the code and observe the output. Here advertisement will
not raotate or display continuously because time is not used . If you want to check that
advertisement is randomly coming or not just click on refresh button , it will
automatically display other advertisement.
In next post I will
come back with AdRotator in asp.net using DataBase file.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.