Rich控件二

2018-06-17 21:38:11来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

Calendar控件 

使用案例:

Default.aspx中:

 1 <div>
 2 
 3   <h1>Calendar控件</h1>
 4 
 5     <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" 
 6 
 7                 DayNameFormat="Shortest" Font-Names="VerDana" Font-Size="8pt" ForeColor="#663399" Height="300px"
 8 
 9                 ShowGridLines="true" width="400px" OnDayRender="Calendar1_DayRender" OnSelectionChanged="Calendar1_SelectionChanged" 
10 
11       OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">
12 
13                 <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="true"/>
14 
15                 <SelectorStyle BackColor="#FFCC66"/>
16 
17                 <TodayDayStyle BackColor="#FFCC66" ForeColor="White"/>
18 
19                 <OtherMonthDayStyle BackColor="#CC9966"/>
20 
21                 <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC"/>
22 
23                 <DayHeaderStyle BackColor="#FFCC66" Font-Bold="true" Height="1px"/>
24 
25                 <TitleStyle BackColor="#660000" Font-Bold="true" Font-Size="9pt" ForeColor="#FFFFCC"/>
26 
27             </asp:Calendar>
28 
29   <br/>
30 
31   <br/>
32 
33   <asp:Label ID="Label1" runat="server"/>
34 
35 </div>

在Default.aspx.cs中:

 1 protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
 2 {
 3   //定义假日显示样式1
 4   Style vacStyle1 = new Style();
 5   vacStyle1.BackColor = System.Drawing.Color.Violet;
 6   vacStyle1.BorderColor = System.Drawing.Color.Wheat;
 7   vacStyle1.BorderWidth = 4;
 8 
 9   //定义假日显示样式1
10   Style vacStyle2 = new Style();
11   vacStyle2.BackColor = System.Drawing.Color.Red;
12   vacStyle2.BorderColor = System.Drawing.Color.PaleVioletRed;
13   vacStyle2.BorderWidth = 4;
14 
15   //定义周末显示样式
16   Style weekStyle = new Style();
17   weekStyle.BackColor = System.Drawing.Color.Gold;
18   string title1 = "十一长假";//假日提示内容
19   string title2 = "中秋节";
20 
21   if ((e.Day.Date == new DateTime(2015, 9, 27)))
22   {
23     //应用样式到假日
24     e.Cell.ApplyStyle(vacStyle2);
25     //定义假日显示内容,并为假日提供链接
26     Label Label1 = new Label();
27     Label1.Text = "<br>" + "<a href=" + e.SelectUrl + ">" + title2 + "</a>";
28     e.Cell.Controls.Add(Label1);
29   }
30 
31   if ((e.Day.Date >= new DateTime(2015, 10, 1)) && (e.Day.Date <= new DateTime(2015, 10, 7)))
32   {
33     //应用样式到假日
34     e.Cell.ApplyStyle(vacStyle1);
35     //定义假日显示内容,并为假日提供链接
36     Label Label1 = new Label();
37     Label1.Text = "<br>" + "<a href=" + e.SelectUrl + ">" + title1 + "</a>";
38     e.Cell.Controls.Add(Label1);
39   }
40   else if (e.Day.IsWeekend)
41     e.Cell.ApplyStyle(weekStyle);
42 
43   DateTime mytime = new DateTime(2015, 10, 1);
44   if (e.Day.Date == mytime)
45     e.Day.IsSelectable = true;
46   else
47     e.Day.IsSelectable = false;
48  }
49 
50 protected void Calendar1_SelectionChanged(object sender, EventArgs e)
51 {
52   this.Label1.Text = "今天是:" + this.Calendar1.TodaysDate.ToShortDateString() + "<br>" + "你选择的日期是:"+ 
53     this.Calendar1.SelectedDate.ToShortDateString();
54 }
55 
56 protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
57 {
58   if (e.NewDate.Month > e.PreviousDate.Month)
59   {
60     this.Label1.Text = "下一个月";
61   }
62   else
63   {
64     this.Label1.Text = "上一个月";
65   }
66 }

AdRotator控件

读取XML文件中的广告信息

AdRotator1.ad中:

 1 <Advertisements xmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File">
 2   <Ad xmlns="">
 3     <ImageUrl>~/Images/Sunset.jpg</ImageUrl>
 4     <AlternateText>落日</AlternateText>
 5     <Impressions>80</Impressions>
 6   </Ad>
 7   <Ad xmlns="">
 8     <ImageUrl>~/Images/Water hills.jpg</ImageUrl>
 9     <AlternateText>荷塘</AlternateText>
10     <Impressions>60</Impressions>
11   </Ad>
12   <Ad xmlns="">
13     <ImageUrl>~/Images/Winter.jpg</ImageUrl>
14     <AlternateText>冰山</AlternateText>
15     <Impressions>90</Impressions>
16   </Ad>
17 </Advertisements>

Default.aspx中:

1 <div>
2   <asp:AdRotator ID="AdRotator1" runat="server"AdvertisementFile="~/App_Data/AdRotator1.ad" />
3 </div>

读取数据库文件中的广告信息

在Web.config中:

1 <connectionStrings>
2   <add name="ConnectionString1" connectionString="Data Source=追风的蜗牛;Initial Catalog=Adrotator;Integrated Security=True"/>
3 </connectionStrings>

在Dfault.aspx.cs中:

1 <div>
2   <asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="SqlDataSource1" />
3   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:ConnectionString1%>" 
4     SelectCommand="SELECT [ID],[ImageUrl],[NavigateUrl],[Impressions],[AlternateText] FROM Advertisements">
5   </asp:SqlDataSource>
6 </div>

MultiViewView控件

Default.aspx中:

 1 <div>
 2   <asp:Label Text="请选择显示样式:" runat="server"></asp:Label>
 3   <br/>
 4   <asp:RadioBUtton ID="RadioButton1" runat="server" AutoPostBack="true" Text="样式1" GroupName="Group1" 
 5     OnCheckedChanged="RadioButton_CheckedChanged" />  
 6   <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="true" Text="样式2" GroupName="Group1" 
 7     OnCheckedChanged="RadioButton_CheckedChanged" />
 8   <hr/>
 9   <asp:MultiView ID="MultiView1" runat="server">
10     <asp:View ID="View1" runat="server">
11       <asp:Label ID="Label1" Text="样式一" runat="server"></asp:Label>
12     </asp:View>
13     <asp:View ID="View2" runat="server">
14       <asp:Label ID="Label2" Text="样式二" runat="server"></asp:Label>
15     </asp:View>
16   </asp:MultiView>
17 </div>

Default.aspx.cs中:

1 protected void RadioButton_CheckedChanged(object sender, EventArgs e)
2 {
3   if (this.RadioButton1.Checked)
4     MultiView1.ActiveViewIndex = 0;
5   else if (this.RadioButton2.Checked)
6     MultiView1.ActiveViewIndex = 1;
7 }

Wizard控件

Default.aspx中:

 1 <div>
 2   <asp:Wizard ID="Wizard1" runat="server">
 3     <WizardSteps>
 4       <asp:WizardStep Title="step1" runat="server">
 5         <asp:Label runat="server" Text="姓名:"/>
 6         <asp:TextBox ID="TextBox1" runat="server"/>
 7       </asp:WizardStep>
 8       <asp:WizardStep Title="step2" runat="server">
 9         <asp:Label runat="server" Text="性别:"/>
10         <asp:TextBox runat="server" ID="TextBox2"/>
11       </asp:WizardStep>
12       <asp:WizardStep Title="step3" runat="server">
13         <asp:Label runat="server" Text="电话:"/>
14         <asp:TextBox ID="TextBox3" runat="server" />
15       </asp:WizardStep>
16     </WizardSteps>
17   </asp:Wizard>
18 </div>

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:主题

下一篇:C#--静态构造函数