在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
广告控件的使用: 广告文件是一个XML文件,广告文件中所有的标签属性被分析后放到adProperties字典中,用以属性编辑。 ads.xml 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--广告文件是一个XML文件--> 3 <Advertisements> 4 <Ad> 5 <ImageUrl>4rwbgzby.gif</ImageUrl> 6 <NavigateUrl>http://www.cnblogs.com/daomul/</NavigateUrl> 7 <AlternateText>Text_01</AlternateText> 8 <KeyWord>one</KeyWord> 9 <Impressions>40</Impressions> 10 <Aniaml>I'm using adRotator No.1</Aniaml> 11 </Ad> 12 13 <Ad> 14 <ImageUrl>banner.jpg</ImageUrl> 15 <NavigateUrl>http://www.cnblogs.com/daomul/</NavigateUrl> 16 <AlternateText>Text_02</AlternateText> 17 <KeyWord>two</KeyWord> 18 <Impressions>40</Impressions> 19 <Aniaml>I'm using adRotator No.2</Aniaml> 20 </Ad> 21 22 <Ad> 23 <ImageUrl>cvtxlkw4.gif</ImageUrl> 24 <NavigateUrl>http://www.cnblogs.com/daomul/</NavigateUrl> 25 <AlternateText>Text_03</AlternateText> 26 <KeyWord>three</KeyWord> 27 <Impressions>30</Impressions> 28 <Aniaml>I'm using adRotator No.3</Aniaml> 29 </Ad> 30 31 </Advertisements> adRotator.aspx.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 8 public partial class myTest_advertisement : System.Web.UI.Page 9 { 10 protected void Page_Load(object sender, EventArgs e) 11 { 12 13 } 14 protected void ad_Created(object sender, AdCreatedEventArgs e) 15 { 16 if ((string)e.AdProperties["Animal"] != "") 17 Label1.Text = (string)e.AdProperties["Aniaml"]; 18 else 19 Label1.Text = "n.a."; 20 } 21 } adRotator.aspx 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adRotator.aspx.cs" Inherits="myTest_advertisement" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title>Using adRotator</title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div> 12 <h1>Adrotator Control</h1> 13 <%--Adrotator文件--%> 14 <asp:AdRotator ID="AdRotator1" runat="server" 15 Target="_blank" 16 AdvertisementFile="ads.xml" 17 onAdCreated="ad_Created"/> 18 <br /> 19 Animal: 20 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 21 </div> 22 </form> 23 </body> 24 </html>
1、重构菜单:提取方法(Ctrl+R,Ctrl+M) 封装字段(Ctrl+R,Ctrl+F) 2、字典中的关键字是Animal, 该值转化为字符串, (string).AdProperties["Aniaml"]
|
请发表评论