Điều khiển Advertisements(Trình bày quảng cáo Adrotator)

Một phần của tài liệu GIÁO TRÌNH ASP. NET potx (Trang 57 - 60)

Cho phép bạn hiển thị các ảnh quảng cáo khác nhau trong 1 trang. bạn có thể lưu trữ các quảng cáo của bạn trong 1 file XML hoặc một bảng cơ sở dữ liệu.

. Các thuộc tính

Thuộc tính Ý nghĩa

AdvertisementFile Cho phép bạn chỉ định đến đường dẫn file XML chứa đựng danh sách ảnh quảng cáo AlternateTextField Cho phép chỉ định đến tên của trường để hiển thị nội dung thay thế khi ảnh quảng cáo vì

một lý do nào đó không hiển thị được

DataMenber Cho phép ràng buộc đến một thành viên cơ sở dữ liệu của nguồn cơ sở dữ liệu DataSource Chỉ rõ cở sở dữ liệu chứa danh sách các banner quảng cáo

DataSourceID Ràng buộc đến 1 cơ sở dữ liệu

ImgUrlFile Chỉ rõ đến trường chứa đường dẫn banner quảng cáo KeywordFilter Cho phép bạn lọc quảng cáo bởi 1 từ khoá

NavigateUrlField Chỉ rõ đến tên của trường chứa các liên kết quảng cáo

Target Cho phép bạn mở ra một cửa sổ mới khi nhấn vào banner quảng cáo

Sự kiện

 AdCreated: Xảy ra sau khi điều khiển Adrotator lựa chọn một quảng cáo nhưng trước khi điều khiển AdRotator đưa ra quảng cáo.

Chú ý rằng điều khiển AdRotator chứa đựng thuộc tính KeywordFilter bạn có thể cung cấp mỗi banner quảng cáo với 1 từ khoá sau đó khi trình bày quảng cáo chúng ta có thể lọc những quảng cáo theo điều kiện để hiển thị.

Ví dụ như trên trang của bạn, bạn cần trình bầy quảng cáo ở 4 vị trí trên banner(top) của trang, bên trai, phải và phía chân(bottom) của trang. Khi đó bạn gán với mỗi ảnh quảng cáo một từ khoá(ví dụ tương ứng với 1- top, 2- right, 3 – bottom, 4 - left) và khi trình bầy trong điều khiển AdRotator ta có thể dùng thuộc tính KeywordFilter để lọc và trình bày.

Ví dụ 1: Trên trang web của bạn trình bầy quảng cáo ở hai vị trí(trên đầu và bên phải của trang) layout như sau

Code 5a: AdRotatorXML.aspx

<%@PageLanguage="VB"AutoEventWireup="false"CodeFile="AdRotatorXML.aspx.vb" Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml"> <headrunat="server">

<title>AdRotator XML</title>

<styletype="text/css">

#wrapper {width: 782px; margin: 0auto;}

#border { border: 1pxsolid#8ECE5F; margin: 20px0px5px0px; background-color: #ffffff; min- height: 776px; float: right; width: 780px;}

#header {background-color:#BECEF5; text-align: width:782px; height:100px; center;margin:6px0px 0px0px;}

#right{background-color:#BECEF5; width:170px;margin: 6px0px0px4px; height:300px; float:right} .box{ float:right;padding:10px; border-left:solid1pxblack;}

</style> </head> <body>

<formid="form1"runat="server">

<divid="wrapper">

<divid="border">

<divid="header">

<asp:AdRotatorID="advbanner"AdvertisementFile="~/App_Data/AdList.xml" KeywordFilter="banner"runat="server"/> (adsbygoogle = window.adsbygoogle || []).push({});

</div>

<divid="right">

<asp:AdRotatorID="AdRotator1"AdvertisementFile="~/App_Data/AdList.xml" KeywordFilter="right"runat="server"/>

</div>

<divclass="box">

<asp:AdRotatorID="AdRotator2"AdvertisementFile="~/App_Data/AdList.xml" KeywordFilter="right"runat="server"/> </div> </div> </div> </div> </form> </body> </html>

Nội dung File XML Code 5b.

<?xml version="1.0" encoding="utf-8" ?> <Advertisements>

<Ad>

<ImageUrl>~/Advertisement/images/banner.png</ImageUrl> <Width>782</Width>

<Height>100</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Diễn đàn ĐH Hoa Sen</AlternateText> <Impressions>50</Impressions>

<Keyword>banner</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/banner2.gif</ImageUrl> <Width>782</Width>

<Height>100</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Diễn đàn ĐH Hoa Sen</AlternateText> <Impressions>50</Impressions>

<Keyword>banner</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh1.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh1.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

</Ad> <Ad>

<ImageUrl>~/Advertisement/images/anh2.gif</ImageUrl> <Width>150</Width> (adsbygoogle = window.adsbygoogle || []).push({});

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh3.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh4.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh5.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

<Ad>

<ImageUrl>~/Advertisement/images/anh6.gif</ImageUrl> <Width>150</Width>

<Height>150</Height>

<NavigateUrl>http://www.sinhvienhoasen.com</NavigateUrl> <AlternateText>Box Advertisement 1</AlternateText> <Impressions>50</Impressions>

<Keyword>right</Keyword> </Ad>

</Advertisements>

Cách thực hiện bạn đưa XML có cấu trúc như code 5b, sau đó trong trang AdRotatorXML.aspx bạn đưa điều khiển AdRotator vào và đặt cho nó hai thuộc tính AdvertisementFile chỉ đến File XML bạn vừa tạo, và thuộc tính KeywordFilter theo thẻ Keyword trong file XML.

Một phần của tài liệu GIÁO TRÌNH ASP. NET potx (Trang 57 - 60)