2011-07-29 16 views
1

HeeyスタッカーASP.NETカレンダーコントロール

私は私が月から変更日をクリックしたら、それは前に戻って月に変更私のカレンダーすべてが正常に動作します

これまでの小さな問題を抱えていますどのように私はこれを修正することができます。 TYすべて

これは私が特別な日に私のカレンダーにデータを挿入する場合、私は上をクリックした場合ので、それは文句を言わない、直接私の挿入されたデータを表示しなければならなかった

  using System; 
      using System.Configuration; 
      using System.Data; 
      using System.Linq; 
      using System.Web; 
      using System.Web.Security; 
      using System.Web.UI; 
      using System.Web.UI.HtmlControls; 
      using System.Web.UI.WebControls; 
      using System.Web.UI.WebControls.WebParts; 
      using System.Data.SqlClient; 
      using System.Collections; 
      using iTextSharp.text; 
      using iTextSharp.text.pdf; 
      using iTextSharp.text.html; 
      using System.IO; 
      using System.Net; 
using System.Collections.Generic; 

     public partial class _Default : BasePage 
     { 

      Hashtable _scheduleData; 

      DataView todo = new DataView(); 

      protected void Page_Load(object sender, EventArgs e) 
      { 

       if (Calendar1.SelectedDate == DateTime.Today) 
       { 
        Calendar1.SelectedDate.Date.ToShortDateString(); 
       } 
       _scheduleData = GetSchedule(); 

       Calendar1.Caption = "<br/>Het is vandaag:<br />" + DateTimeOffset.Now.LocalDateTime.ToShortDateString() + "<h1>Plan School Activiteiten</h1>"; 

       Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday; 
       Calendar1.NextPrevFormat = NextPrevFormat.FullMonth; 
       Calendar1.NextPrevStyle.CssClass = "NextPrevMonthText"; 
       Calendar1.TitleFormat = TitleFormat.MonthYear; 
       Calendar1.TitleStyle.CssClass = "TitleStyle"; 
       //Calendar1.TitleStyle.BackColor = System.Drawing.Color.Transparent; 
       Calendar1.ShowGridLines = true; 
       Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Left; 
       Calendar1.DayStyle.CssClass = "Daysoftheweek"; 
       Calendar1.DayStyle.VerticalAlign = VerticalAlign.Top; 
       Calendar1.DayStyle.Height = new Unit(75); 
       Calendar1.DayStyle.Width = new Unit(100); 
       Calendar1.TodayDayStyle.CssClass = "Today"; 
       Calendar1.TodaysDate.ToShortDateString(); 
       Calendar1.VisibleDate = Calendar1.TodaysDate; 
       Calendar1.SelectedDayStyle.CssClass = "SelectStyle"; 
       Calendar1.SelectedDayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffea44"); 
       Calendar1.SelectedDayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000"); 

      } 

      private Hashtable GetSchedule() 
      { 
       Hashtable schedule = new Hashtable(); 

       string cnnString = ConfigurationManager.ConnectionStrings["Stefan"].ConnectionString; 
       DataTable dt = new DataTable(); 

       using (SqlConnection con = new SqlConnection(cnnString)) 
       using (SqlCommand cmd = new SqlCommand("select * from [Calender]", con)) 
       { 
        using (SqlDataAdapter da = new SqlDataAdapter(cmd)) 
        { 
         da.Fill(dt); 


        } 
        con.Open(); 
        cmd.ExecuteNonQuery(); 
       } 

        Dictionary<string, int> schedulesDateCount = new Dictionary<string, int>(); 

        for (int i = 0; i < dt.Rows.Count; i++) 
        { 
         string date = Convert.ToDateTime(dt.Rows[i]["date"]).ToShortDateString(); 

         if (!schedulesDateCount.ContainsKey(date)) 
          schedulesDateCount[date] = 0; 

         if (schedulesDateCount[date] < 3) 
         { 
          schedule[date] = (schedule[date] != null ? schedule[date].ToString(): "") + Server.HtmlEncode(dt.Rows[i]["todo"].ToString()) + "<br />" + dt.Rows[i]["time"].ToString() + "<br />"; 
          schedulesDateCount[date] = schedulesDateCount[date] + 1; 
         } 
        } 
        return schedule; 

       } 


      void Page_PreRender() 
      { 

       todo = (DataView)calendarSrc.Select(DataSourceSelectArguments.Empty); 
       todo.Sort = "date"; 

      } 

      protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) 
      { 

       string date = e.Day.Date.ToShortDateString(); 
       if (_scheduleData[date] != null) 
       { 

        Literal lit = new Literal(); 
        lit.Text = "<br />"; 
        e.Cell.Controls.Add(lit); 

        Label lbl = new Label(); 
        lbl.Text = (string)_scheduleData[e.Day.Date.ToShortDateString()]; 
        lbl.Font.Size = new FontUnit(FontSize.Small); 
        e.Cell.Controls.Add(lbl); 

       } 

      } 

      protected void Calendar1_SelectionChanged(object sender, EventArgs e) 
      { 
       FormView1.ChangeMode(FormViewMode.Edit); 
      } 

      protected void butAddNew_Click(object sender, EventArgs e) 
      { 
       FormView1.ChangeMode(FormViewMode.Insert); 
      } 
      protected void todoSrc_Inserted(object sender, SqlDataSourceStatusEventArgs e) 
      { 
       Refresh(); 
      } 
      protected void todoSrc_Deleted(object sender, SqlDataSourceStatusEventArgs e) 
      { 
       Refresh(); 
      } 
      protected void todoSrc_Updated(object sender, SqlDataSourceStatusEventArgs e) 
      { 
       Refresh(); 
      } 

      private void Refresh() 
      { 
       Response.Redirect(Request.RawUrl); 
      } 

@Tim Schmelter

私のコードですそれその番組よりも一日が、私はので、私はこの

protected void todoSrc_Deleted(object sender, SqlDataSourceStatusEventArgs e) 
{ 
    Refresh(); 
} 
protected void todoSrc_Updated(object sender, SqlDataSourceStatusEventArgs e) 
{ 
    Refresh(); 
} 

private void Refresh() 
{ 
    Response.Redirect(Request.RawUrl); 
} 

答えて

2

をした私は、これが理由であるかどうかわからないんだけど、あなただけ場合は、あなたのカレンダーのデフォルトの初期化を行う必要がありたくありません。

if(!Page.IsPostBack){ 
     if (Calendar1.SelectedDate == DateTime.Today) 
     { 
      Calendar1.SelectedDate.Date.ToShortDateString(); 
     } 
     _scheduleData = GetSchedule(); 

     Calendar1.Caption = "<br/>Het is vandaag:<br />" + DateTimeOffset.Now.LocalDateTime.ToShortDateString() + "<h1>Plan School Activiteiten</h1>"; 

     Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday; 
     Calendar1.NextPrevFormat = NextPrevFormat.FullMonth; 
     Calendar1.NextPrevStyle.CssClass = "NextPrevMonthText"; 
     Calendar1.TitleFormat = TitleFormat.MonthYear; 
     Calendar1.TitleStyle.CssClass = "TitleStyle"; 
     //Calendar1.TitleStyle.BackColor = System.Drawing.Color.Transparent; 
     Calendar1.ShowGridLines = true; 
     Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Left; 
     Calendar1.DayStyle.CssClass = "Daysoftheweek"; 
     Calendar1.DayStyle.VerticalAlign = VerticalAlign.Top; 
     Calendar1.DayStyle.Height = new Unit(75); 
     Calendar1.DayStyle.Width = new Unit(100); 
     Calendar1.TodayDayStyle.CssClass = "Today"; 
     Calendar1.TodaysDate.ToShortDateString(); 
     Calendar1.VisibleDate = Calendar1.TodaysDate; 
     Calendar1.SelectedDayStyle.CssClass = "SelectStyle"; 
     Calendar1.SelectedDayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffea44"); 
     Calendar1.SelectedDayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000"); 
} 
+0

Tyの非常に多く、私はあなたが私はそれが前に戻っ月に変更する何かを挿入するために、月からの変更が、私はその選択として、インサートが正しい場所にsucced場合 –

+0

はありません、それはスティル仕事didntは知っているようにこれをしようとします –

+0

@デザイナー:なぜReponse.Redirect(sameUrl)でページをリロードするのですか?これは '!postBack'アプローチを破壊します。 –

関連する問題