Calendar控件
使用案例:
在Default.aspx中:
1<div>23<h1>Calendar控件</h1>45<asp:CalendarID="Calendar1"runat="server"BackColor="#FFFFCC"BorderColor="#FFCC66"BorderWidth="1px"67DayNameFormat="Shortest"Font-Names="VerDana"Font-Size="8pt"ForeColor="#663399"Height="300px"89ShowGridLines="true"width="400px"OnDayRender="Calendar1_DayRender"OnSelectionChanged="Calendar1_SelectionChanged"1011OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">1213<SelectedDayStyleBackColor="#CCCCFF"Font-Bold="true"/>1415<SelectorStyleBackColor="#FFCC66"/>1617<TodayDayStyleBackColor="#FFCC66"ForeColor="White"/>1819<OtherMonthDayStyleBackColor="#CC9966"/>2021<NextPRevStyleFont-Size="9pt"ForeColor="#FFFFCC"/>2223<DayHeaderStyleBackColor="#FFCC66"Font-Bold="true"Height="1px"/>2425<TitleStyleBackColor="#660000"Font-Bold="true"Font-Size="9pt"ForeColor="#FFFFCC"/>2627</asp:Calendar>2829<
br/>3031<
br/>3233<asp:LabelID="Label1"runat="server"/>3435</div>
在Default.aspx.cs中:
1protectedvoidCalendar1_DayRender(objectsender, DayRenderEventArgs e)2{3//定义假日显示样式14Style vacStyle1 =newStyle();5vacStyle1.BackColor =System.Drawing.Color.Violet;6vacStyle1.BorderColor =System.Drawing.Color.Wheat;7vacStyle1.BorderWidth =4;89//定义假日显示样式110Style vacStyle2 =newStyle();11vacStyle2.BackColor =System.Drawing.Color.Red;12vacStyle2.BorderColor =System.Drawing.Color.PaleVioletRed;13vacStyle2.BorderWidth =4;1415//定义周末显示样式16Style weekStyle =newStyle();17weekStyle.BackColor =System.Drawing.Color.Gold;18stringtitle1 ="十一长假";//假日提示内容19stringtitle2 ="中秋节";2021if((e.Day.Date ==newDateTime(2015,9,27)))22{23//应用样式到假日24e.Cell.ApplyStyle(vacStyle2);25//定义假日显示内容,并为假日提供链接26Label Label1 =newLabel();27Label1.Text ="<br>"+"<a href="+ e.SelectUrl +">"+ title2 +"</a>";28e.Cell.Controls.Add(Label1);29}3031if((e.Day.Date >=newDateTime(2015,10,1)) && (e.Day.Date <=newDateTime(2015,10,7)))32{33//应用样式到假日34e.Cell.ApplyStyle(vacStyle1);35//定义假日显示内容,并为假日提供链接36Label Label1 =newLabel();37Label1.Text ="<br>"+"<a href="+ e.SelectUrl +">"+ title1 +"</a>";38e.Cell.Controls.Add(Label1);39}40elseif(e.Day.IsWeekend)41e.Cell.ApplyStyle(weekStyle);4243DateTime mytime =newDateTime(2015,10,1);44if(e.Day.Date ==mytime)45e.Day.IsSelectable =true;46else47e.Day.IsSelectable =false;48}4950protectedvoidCalendar1_SelectionChanged(objectsender, EventArgs e)51{52this.Label1.Text ="今天是:"+this.Calendar1.TodaysDate.ToShortDateString() +"<br>"+"你选择的日期是:"+53this.Calendar1.SelectedDate.ToShortDateString();54}5556protectedvoidCalendar1_VisibleMonthChanged(objectsender, MonthChangedEventArgs e)57{58if(e.NewDate.Month >e.PreviousDate.Month)59{60this.Label1.Text ="下一个月";61}62else63{64this.Label1.Text ="上一个月";65}66}
AdRotator控件
读取xml文件中的广告信息
在AdRotator1.ad中:
1<Advertisementsxmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File">2<Adxmlns="">3<ImageUrl>~/Images/Sunset.jpg</ImageUrl>4<AlternateText>落日</AlternateText>5<Impressions>80</Impressions>6</Ad>7<Adxmlns="">8<ImageUrl>~/Images/Water hills.jpg</ImageUrl>9<AlternateText>荷塘</AlternateText>10<Impressions>60</Impressions>11</Ad>12<Adxmlns="">13<ImageUrl>~/Images/Winter.jpg</ImageUrl>14<AlternateText>冰山</AlternateText>15<Impressions>90</Impressions>16</Ad>17</Advertisements>
在Default.aspx中:
1<div>2<asp:AdRotatorID="AdRotator1"runat="server"AdvertisementFile="~/App_Data/AdRotator1.ad"/>3</div>
读取数据库文件中的广告信息
在Web.config中:
1<connectionStrings>2<addname="ConnectionString1"connectionString="Data Source=追风的蜗牛;Initial Catalog=Adrotator;Integrated Security=True"/>3</connectionStrings>
在Dfault.aspx.cs中:
1<div>2<asp:AdRotatorID="AdRotator1"runat="server"DataSourceID="SqlDataSource1"/>3<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStrings:ConnectionString1%>"4SelectCommand="SELECT [ID],[ImageUrl],[NavigateUrl],[Impressions],[AlternateText] FROM Advertisements">5</asp:SqlDataSource>6</div>
MultiView和View控件
在Default.aspx中:
1<div>2<asp:LabelText="请选择显示样式:"runat="server"></asp:Label>3<
br/>4<asp:RadioBUttonID="RadioButton1"runat="server"AutoPostBack="true"Text="样式1"GroupName="Group1"5OnCheckedChanged="RadioButton_CheckedChanged"/>6<asp:RadioButtonID="RadioButton2"runat="server"AutoPostBack="true"Text="样式2"GroupName="Group1"7OnCheckedChanged="RadioButton_CheckedChanged"/>8<hr/>9<asp:MultiViewID="MultiView1"runat="server">10<asp:ViewID="View1"runat="server">11<asp:LabelID="Label1"Text="样式一"runat="server"></asp:Label>12</asp:View>13<asp:ViewID="View2"runat="server">14<asp:LabelID="Label2"Text="样式二"runat="server"></asp:Label>15</asp:View>16</asp:MultiView>17</div>
在Default.aspx.cs中:
1protectedvoidRadioButton_CheckedChanged(objectsender, EventArgs e)2{3if(this.RadioButton1.Checked)4MultiView1.ActiveViewIndex =0;5elseif(this.RadioButton2.Checked)6MultiView1.ActiveViewIndex =1;7}
Wizard控件
在Default.aspx中:
1<div>2<asp:WizardID="Wizard1"runat="server">3<WizardSteps>4<asp:WizardStepTitle="step1"runat="server">5<asp:Labelrunat="server"Text="姓名:"/>6<asp:TextBoxID="TextBox1"runat="server"/>7</asp:WizardStep>8<asp:WizardStepTitle="step2"runat="server">9<asp:Labelrunat="server"Text="性别:"/>10<asp:TextBoxrunat="server"ID="TextBox2"/>11</asp:WizardStep>12<asp:WizardStepTitle="step3"runat="server">13<asp:Labelrunat="server"Text="电话:"/>14<asp:TextBoxID="TextBox3"runat="server"/>15</asp:WizardStep>16</WizardSteps>17</asp:Wizard>18</div>