65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 AJAX.NET 和 AjaxControlToolkit 的波斯历 Web 控件

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.80/5 (29投票s)

2007年1月28日

CPOL
viewsIcon

128438

downloadIcon

4796

这是一个具有完整功能的波斯网络日历,类似于 ASP.NET 2.0 Calendar 控件。

Sample Image - PersianCalendarControl.jpg

引言

这是一个具有完整功能的波斯历 Web 自定义控件,类似于 ASP.NET 2.0 Calendar。

在演示项目中,我使用了 AJAX.NET 和 AjaxControlToolkit(http://ajax.asp.net/downloads/default.aspx?tabid=47)。

要检索和设置波斯日期,请使用 "SelectedDatePersian" 属性。您还可以使用 "SelectedDate" 属性来检索以公历格式选择的日期。此控件支持日期范围选择。要启用此功能,您必须将 "SelectionMode" 属性设置为 "DayWeekMonth" 或 "DayWeek",并使用 "SelectedDates" 属性来检索选定的日期范围。

PersianCalendar1.SelectionMode = CalendarSelectionMode.DayWeekMonth;
List<DateTime> selectedDates = 
    (List<DateTime>)PersianCalendar1.SelectedDates.GetEnumerator();

要格式化选定的波斯日期,请使用 "SelectedPersianDateFormat"。

PersianCalendar1.SelectedPersianDateFormat == 
                    PersianDateStringType.LongReverse;

PersianCalendar1.SelectedPersianDateFormat == PersianDateStringType.Short;

此示例演示了如何将 PersianCalendar 控件与 AJAX UpdatePanel 结合使用。

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" 
            Inherits="AJAXEnabledWebApplication1._Default" %>
<%@ Register Assembly="KingOf.Net.Web.UI.WebControls.PersianCalendar" 
    Namespace="KingOf.Net.Web.UI.WebControls" TagPrefix="KingOfDotNet" %>
<%@ Register Assembly="AjaxControlToolkit" 
    Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
      Persian Calendar Web Control Compatible With Ajax.Net<br />
      <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True">
    </asp:TextBox><br />
      <asp:ScriptManager ID="ScriptManager1" runat="server" />
      <div>
          <cc1:PopupControlExtender ID="PopupControlExtender1" 
        runat="server" TargetControlID="TextBox1"
                PopupControlID="Panel1" Position="Bottom">
          </cc1:PopupControlExtender>
          <asp:Panel ID="Panel1" runat="server" CssClass="popupControl">
              <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                  <ContentTemplate>
                      <center>
                          <KingOfDotNet:PersianCalendar ID="PersianCalendar1" 
                        runat="server" BackColor="#FFFFCC"
                              BorderColor="#FFCC66" BorderWidth="1px" 
                        DayNameFormat="Shortest" Font-Names="Verdana"
                              Font-Size="8pt" ForeColor="#663399" 
                        Height="200px" OnSelectionChanged=
                            "PersianCalendar1_SelectionChanged"
                              SelectedDate="2000-01-01" ShowGridLines="True" 
                            VisibleDate="2000-01-01" Width="220px"
                              SelectedPersianDateFormat="Long">
                              <SelectedDayStyle BackColor="#CCCCFF" 
                                Font-Bold="True" />
                              <TodayDayStyle BackColor="#FFCC66" 
                                ForeColor="White" />
                              <SelectorStyle BackColor="#FFCC66" />
                              <OtherMonthDayStyle ForeColor="#CC9966" />
                              <NextPrevStyle Font-Size="9pt" 
                                ForeColor="#FFFFCC" />
                              <DayHeaderStyle BackColor="#FFCC66" 
                            Font-Bold="True" Height="1px" />
                              <TitleStyle BackColor="#990000" 
                            Font-Bold="True" Font-Size="9pt" 
                            ForeColor="#FFFFCC" />
                          </KingOfDotNet:PersianCalendar>
                          &nbsp;
                      </center>
                  </ContentTemplate>
              </asp:UpdatePanel>
          </asp:Panel>
      </div>
  </form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using KingOf.Net.Web.UI.WebControls;

namespace AJAXEnabledWebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void PersianCalendar1_SelectionChanged
                                (object sender, EventArgs e)
        {
            PopupControlExtender1.Commit(PersianCalendar1.SelectedDatePersian);
        }
    }
}
© . All rights reserved.