vs2005中日历控件 asp:Calendar 点某一天时 链接到另一个页面,并把参数如2007-12-21传过去 ?在线等
vs2005中日历控件 asp:Calendar 点某一天时 链接到另一个页面,并把参数如2007-12-21传过去怎么实现,请给出实例代码。 --------------------编程问答--------------------
--------------------编程问答-------------------- 链接到另一个页面,可以用Response.Redirect或Server.Transfer --------------------编程问答-------------------- <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
//SelectionChanged事件
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
string str = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
}
</asp:Calendar>
*************************************************************
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Response.Redirect("default4.aspx?thedate="+this.Calendar1.SelectedDate.ToShortDateString());
} --------------------编程问答-------------------- 用跨页面回发啊~!
有日历控件的页面 default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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>无标题页</title>
<script type="text/javascript" language="javascript">
public Calendar ca
{
get{
return Calendar1;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" PostBackUrl="~/Default3.aspx"/>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
接收页面default3.aspx
页面代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ PreviousPageType VirtualPath="~/Default2.aspx" %>
<!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
后置代码:
protected void Page_Load(object sender, EventArgs e)
{
if(PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
Calendar cc = PreviousPage.FindControl("Calendar1") as Calendar;
if(cc!=null)
{
Label1.Text = cc.SelectedDate.ToString();
}
}
}
这种跨页面回发是从属性中获得控件的值 --------------------编程问答-------------------- protected void cal1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;
ChineseCalendar cd = new ChineseCalendar(d.Date);
c.Height = 75;
if (!d.IsOtherMonth) //是否当前月
{
c.Controls.Clear(); //去掉日历表自带的日期数字
c.BackColor = System.Drawing.Color.FromName("#FFFBF7"); //当前月份背景颜色
try
{
System.Web.UI.HtmlControls.HtmlGenericControl Link = new System.Web.UI.HtmlControls.HtmlGenericControl();
Link.TagName = "a";
Link.InnerText = e.Day.DayNumberText;
Link.Attributes.Add("href", "Schedule/schaddup.aspx?day=" + d.Date.ToShortDateString());
Link.Attributes.Add("title", d.Date.ToShortDateString());
Link.Attributes.Add("style", "color:#000;font-size:14px;font-weight:bold");
c.Controls.Add(new LiteralControl("<div>"));
c.Controls.Add(Link);
c.Controls.Add(new LiteralControl("</div>"));
c.Controls.Add(new LiteralControl("<div>"));
c.Controls.Add(new LiteralControl(cd.ChineseTwentyFourDay));
c.Controls.Add(new LiteralControl("</div>"));
calshow(d, c, strID);
}
catch (Exception exc)
{
Response.Write(exc.ToString());
}
}
else
{
c.Controls.Clear(); //去掉日历表自带的日期数字
System.Web.UI.HtmlControls.HtmlGenericControl Link = new System.Web.UI.HtmlControls.HtmlGenericControl();
Link.TagName = "a";
Link.InnerText = e.Day.DayNumberText;
Link.Attributes.Add("href", "Schedule/schaddup.aspx?day=" + d.Date.ToShortDateString());
Link.Attributes.Add("style", "color:#cecece;font-size:14px;font-weight:bold");
e.Cell.Controls.Add(Link);
}
if (d.IsToday)
{
c.BackColor = System.Drawing.Color.FromName("#FFFAE0");
}
if (d.IsOtherMonth)
{
c.BackColor = System.Drawing.Color.FromName("#FAFAFA");
}
if (CheckBox1.Checked == true)
{
Show_Friend_Schedule(d, c, 84443);
}
}
自己看着改
补充:.NET技术 , ASP.NET