2011-07-25 12 views
1

私の現在のプロジェクトカレンダー/イベントプランナーに関する質問があります
私は、ストアドプロシージャのない直接データベースにOnClickを送信しています。アイデアは、私のカレンダーの1日のページまたはセルをその日/セルに直接表示する必要があるということです。ボタンでボタンをDirect SQLに送信した後にページを更新する方法は?

<a onClick="window.location.reload()"></a> 

ない私はそのボタンのを必要とするので:私はJavaScriptで試してみましたので、
は今、私は誰かが任意のアイデアを持っていない(それがデータベースに保存されている)、それを見るために日数をクリックする必要がありますもう一つのOnclickイベント。アドバイスをありがとう。 :)

私の現在のコードが背後にある:私が発見した修正がCalender1.DataBindを()ではないに従うようである

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; 

public partial class _Default : System.Web.UI.Page 
{ 
    Hashtable _scheduleData; 

    DataView todo = new DataView(); 

    protected void Page_Load(object sender, EventArgs e) 
    { 

     if (Calendar1.SelectedDate == DateTime.MinValue) 
      Calendar1.SelectedDate = Calendar1.TodaysDate; 

     _scheduleData = GetSchedule(); 

     Calendar1.Caption = "<br/><h1>Plan School Activiteiten<h1><br />"; 

     Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday; 
     Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth; 
     Calendar1.TitleFormat = TitleFormat.MonthYear; 
     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"; 

    } 


    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(); 
     } 


     for (int i = 0; i < dt.Rows.Count; i++) 
     { 
      string date = Convert.ToDateTime(dt.Rows[i]["date"]).ToShortDateString(); 
      schedule[date] = dt.Rows[i]["todo"].ToString(); 
     } 
     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); 
     Calendar1.DataBind(); 
    } 
} 

。 しかし、ここで我々はプロジェクトがうまくいっている助けるため、すべての

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); 
    } 

のTyを行く:)

+0

は、ViewStateを考えていましたボタンを修正する方法を知らない:P –

+1

カレンダーは、OnClickコードが実行される前にデータをレンダリングしているため、変更が表示されないという問題があると思いますか?その場合は、ボタンクリックイベントハンドラで 'Calendar1.DataBind();'を呼び出すだけです。 –

+0

FormViewからOnloadにasp:buttonをPage_LoadとPut DataBind();を入れないでください。 Page_Loadに今すぐうまくいきます。 –

答えて

1

あなたはCalendar1にDataBindを呼び出す必要があります:)私がクリックしたときに

Calendar1.DataBind(); 
関連する問題