ASP.NET 根据当前日期生成当月日历
来源:互联网 发布:qq翻译软件下载 编辑:程序博客网 时间:2024/05/16 00:56
protected void CalendarCreate( DateTime FirstDate)
{
Table1.Rows[0].Cells[1].Text = FirstDate.Year.ToString() + "年" + FirstDate.Month.ToString()+"月";
string labelname="label";
string picname = "";
int labelnameindex=0;
int dayadd = 0;///从当前月份第一天往后累计天数
int weekindex = 0;///表示当前月份的第一天是星期几
int curWeek = 0;
if (Convert.ToInt32(FirstDate.DayOfWeek) != 7)
{
weekindex = Convert.ToInt32(FirstDate.DayOfWeek);
}
int lastmonthindex = 1 - weekindex;
///绘制第二到最后一行日历
for (int i = 2; i <8; i++)
{
for (int j = 0; j < 7; j++)
{
TableCell CurTc = new TableCell();
CurTc = Table1.Rows[i].Cells[j];
//创建日期存放控件label,用来传递每个单元格中datalist的查询参数
Label celllabel = new Label();
celllabel.ID = labelname + (labelnameindex++).ToString();
if (!((i == 2) && (j < weekindex)))
{
picname = FirstDate.AddDays(dayadd).Day.ToString();
curWeek = Convert.ToInt32(FirstDate.AddDays(dayadd).DayOfWeek);
celllabel.Text = FirstDate.AddDays(dayadd++).Date.ToString();
}
else
{
picname = FirstDate.AddDays(lastmonthindex - 1).Day.ToString();
curWeek = Convert.ToInt32(FirstDate.AddDays(lastmonthindex-1).DayOfWeek);;
celllabel.Text = FirstDate.AddDays(lastmonthindex++).Date.ToString();
}
DIV1.Controls.Add(celllabel);//添加到form中,必须输出页面,否则以后的sqldatasource无法访问
//----------------------------------------------------------------------------------------------------------
//首先为此单元格添加相应日历图片,用panel实现用来作为以后列表数据添加的容器
Panel pn = new Panel();
//if (curWeek>=6)
pn.BackImageUrl = "http://localhost/WebSite/imgs/" + picname + ".jpg";
pn.Width = 104;
pn.Height = 124;
CurTc.Controls.Add(pn);
//----------------------------------------------------------------------------------------------------------
//创建sqldatasource
SqlDataSource celldatasource = new SqlDataSource();
form1.Controls.Add(celldatasource);
//添加查询参数,绑定每个单元格中的数据列表像是与单元格所对应日期一致
DataList Dl = new DataList();
ControlParameter pr = new ControlParameter();
pr.Name = "seldate" + (labelnameindex++).ToString();
pr.ControlID = celllabel.ID;
pr.PropertyName = "text";
//添加查询参数之前需要先清除,否则再次提交页面出现参数重复错误
celldatasource.SelectParameters.Clear();
celldatasource.SelectParameters.Add(pr);
celldatasource.SelectParameters[0].Direction = ParameterDirection.Input;
pr.Type = TypeCode.DateTime;
//----------------------------------------------------------------------------------------------------------
celldatasource.ConnectionString = @"Data Source=DEAN-PC/SQLEXPRESS;Initial Catalog=DEANSWORK;Integrated Security=True";
celldatasource.SelectCommand = "SELECT [Ca_id], [Ca_date], [Ca_content], [U_id] FROM [Calendar_content] where [Ca_Date]=@" + pr.Name.ToString();
//----------------------------------------------------------------------------------------------------------
//创建,设置datalist并在表格每个单元格中的panel中加载datalist控件
Dl.DataSource = celldatasource;
Dl.DataKeyField = "Ca_id";
Dl.AlternatingItemTemplate = Page.LoadTemplate("datalist.ascx");
Dl.BackColor = System.Drawing.Color.Transparent;
pn.Controls.Add(Dl);
//----------------------------------------------------------------------------------------------------------
//绑定sqldatasource和datalist的数据集
celldatasource.DataBind();
Dl.DataBind();
//----------------------------------------------------------------------------------------------------------
//如果没有数据输出,单元格内会连并datalist和panel不输出页面,因此对于没有数据集的单元格重新填写其
//图片信息(此处用panel实现竟然依然没有图片,疑惑中,因此暂时用image替代)
if (Dl.Items.Count == 0)
{
Image im = new Image();
im.ImageUrl = "http://localhost/WebSite/imgs/" + picname + ".jpg";
CurTc.Controls.Clear();
//DIV1.Controls.Clear();
DIV1.Controls.Add(celllabel);
CurTc.Controls.Add(im);
}
///------------------------------------------------------
}
}
}
- ASP.NET 根据当前日期生成当月日历
- 根据日期获得当月日历
- js生成当月日历
- 根据当前日期获取当月内所有日期的SQL语句
- 根据输入的日期展示当前月份的日历
- 根据年份和月份打印当月日历
- 获取当前时间,及当月日历
- 根据日期获取当月第一天和当月最后一天
- 根据日期计算当月有多少天
- 根据日期获取当月有几天
- 当月日历
- 做一个日历,输入一个日期,可以生成当月的日历表,并且在对应的天数上面显示*号
- 根据当月数据库自动生成下个月数据库
- 根据当月自动生成下个月数据库--3
- 根据当月自动生成下个月数据库--2
- 根据当月自动生成下个月数据库--1
- 日常练习,根据输入的年月获取当月的日历
- 单击ASP.NET日历控件单元格选择日期
- Dictionary of Analysis, Calculus, and Differential Equations (re-upload)
- C#中动态调用API函数
- OutRun 2006: Coast 2 Coast
- (转)WTL开发者指南(WTL Developer’s Guide翻译2)
- 准备将此Blog与我自己的http://www.kaoiki.com技术帖同步
- ASP.NET 根据当前日期生成当月日历
- SSH框架搭建
- 离成功多远?
- ATl中字符转换宏
- Hibernate+ehcache二级缓存技术
- HRESULT 函数返回值详细介绍
- how to get the value of an control
- UNIX环境下如何应用消息队列实现进程间通信
- 在ASP.NET中,发现的关于string转换的一个小Bug