日期:2014-05-18  浏览次数:20425 次

【【【日历问题,高分相送,急得很啊】】】
private   void   Calendar1_SelectionChanged(object   sender,   System.EventArgs   e)
{
//Response.Write(Calendar1.SelectedDate.ToString( "yyyy-MM-dd "));//语句1
Response.Redirect(Request.CurrentExecutionFilePath+ "?Cdate= "+Calendar1.SelectedDate.ToString( "yyyy-MM-dd "),true);//语句2
}
一个根据点选时间来选择记录的程序,很简单。
当屏蔽语句2     执行语句1   的时候,可以正确Write出今天的日期,
当屏蔽语句1     执行语句2   的时候,无法得到今天的日期,其他任意一天的可以得到。    
也就是说你点击今天的日期,页面好像不执行一样,Calendar1.SelectedDate还是上一次点击的日期。

page_load里面有这两句
if(!this.IsPostBack)
{
Calendar1.DayNameFormat=DayNameFormat.Full;
Calendar1.SelectedDate=DateTime.Now;
}

------解决方案--------------------
Response.Redirect(Request.CurrentExecutionFilePath+ "?Cdate= "+Calendar1.SelectedDate.ToString( "yyyy-MM-dd "),true);//语句2

---> 试试

Response.Redirect(Request.CurrentExecutionFilePath+ "?Cdate= "+Calendar1.SelectedDate.ToString( "yyyy-MM-dd ") + "&rd= " + DateTime.Now.ToString(), true);//语句2

------解决方案--------------------
?号应改成?
------解决方案--------------------
楼上太强了。这么小的差别也能看出来
------解决方案--------------------
?号应改成?
===============
强啊,看的真细~ 学习。。。
------解决方案--------------------
怀疑可能是Response.Redirect跳转了多次,而你没有感觉到,要单步跟踪一下
------解决方案--------------------
1. ?是中文的,改成?

2.你的Page_Load已经有了
Calendar1.SelectedDate=DateTime.Now;

所以再去选日期的时候如果选中的是本日是不会触发Calendar1_SelectionChanged事件的

否则你连着两次点同一天的日期看看,第二次也是不触发的


------解决方案--------------------
跟踪下看看
------解决方案--------------------
看看他的:amandag(高歌) UP下
------解决方案--------------------
你用Redirect来进行页面切换,所以每次跳回本页都会执行if(!IsPostBack)里面的初始化,
将日期设置为今天
我感觉你的Cdate没有用啊。。。应该要判断是否为空,如果不为空就设置为这个日期
------解决方案--------------------
if(!ISPostBack)没用。。。。。
------解决方案--------------------
up
------解决方案--------------------
ding
------解决方案--------------------
顺便问一下,我从数据库里搜索出了日期,怎么使日历上对应的日期显示不同的颜色?
---------------------------
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
if(e.Day.Date == YourDate)
{
e.Cell.BackColor = Color.Red;
}
}
------解决方案--------------------
不同颜色


protected void calAlertInfo_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay d = e.Day;
TableCell c = e.Cell;
c.ToolTip = d.Date.ToString( "yyyy-MM-dd ");

if (dtabInfo != null)
{
if (dtabInfo.Rows.Count != 0)
{
DataRow[] drowInfo = dtabInfo.Select( "AlertDate like '% " + d.Date.ToString( "yyyy-MM-dd ") + "% ' ");
for (int i = 0; i < drowInfo.Length; i++)