/*CalendarForm2.aspx
前台程序
*/
<%@ Page language="c#" Codebehind="CalendarForm2.aspx.cs" AutoEventWireup="false" Inherits="CalendarDemo.CalendarForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>CalendarForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:ListBox id="lbxEmployee" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 80px"
runat="server" Width="144px" Height="264px" Rows="7" AutoPostBack="True"></asp:ListBox>
<asp:Calendar id="calHire" style="Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 384px" runat="server"
Width="312px" Height="160px"></asp:Calendar>
<asp:Label id="lblInfo" style="Z-INDEX: 103; LEFT: 232px; POSITION: absolute; TOP: 352px" runat="server"
Width="152px" Height="24px">display Dates</asp:Label></FONT>
</form>
</body>
</HTML>
/*CalendarForm2.aspx.cs
日历控件使用后台程序
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CalendarDemo
{
/// <summary>
/// CalendarForm2 的摘要说明。
/// </summary>
public class CalendarForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox lbxEmployee;
protected System.Web.UI.WebControls.Calendar calHire;
protected System.Web.UI.WebControls.Label lblInfo;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strCon="server=JOSEN;database=NorthWind;integrated security=true";
string strSql="select EmployeeID,LastName,FirstName,HireDate from Employees";
SqlConnection objCon=new SqlConnection(strCon);
SqlDataAdapter objAdpt=new SqlDataAdapter(strSql,objCon);
DataSet ds=new DataSet();
objAdpt.Fill(ds,"dtEmployee");
if(!IsPostBack)
{
this.lbxEmployee.DataSource=ds;
lbxEmployee.DataTextField="LastName";
lbxEmployee.DataBind();
}
else
{
DateTime datHireDate;
datHireDate=Convert.ToDateTime(ds.Tables["dtEmployee"].Rows[lbxEmployee.SelectedIndex]["HireDate"]);
lblInfo.Text=ds.Tables["dtEmployee"].Rows[lbxEmployee.SelectedIndex]["LastName"].ToString();
this.calHire.VisibleDate=datHireDate;
calHire.SelectedDate=datHireDate;
lblInfo.Text+="hired on "+datHireDate;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
文章来源:
http://www.blogjava.net/kuxiaoku/articles/94808.html
posted on 2007-01-19 00:15
苦笑枯 阅读(219)
评论(0) 编辑 收藏 所属分类:
C#