C# 按钮提交到Direct SQL后如何刷新页面?
我对我当前的项目日历/活动计划有一个问题:C# 按钮提交到Direct SQL后如何刷新页面?,c#,asp.net,visual-studio-2010,calendar,C#,Asp.net,Visual Studio 2010,Calendar,我对我当前的项目日历/活动计划有一个问题: 我有一个OnClick提交到一个没有存储过程的直接数据库。这样做的目的是,日历中当天的页面或单元格需要直接显示在当天/单元格中。 现在我需要点击天数来查看它(它存储在数据库中),有人知道吗,因为我尝试了JavaScript: <a onClick="window.location.reload()"></a> 帮助项目进展顺利的所有方法:)您应该在日历上调用数据绑定1:) 您应该调用日历上的数据绑定1:) 我单击按钮时正在考虑
我有一个OnClick提交到一个没有存储过程的直接数据库。这样做的目的是,日历中当天的页面或单元格需要直接显示在当天/单元格中。
现在我需要点击天数来查看它(它存储在数据库中),有人知道吗,因为我尝试了JavaScript:
<a onClick="window.location.reload()"></a>
帮助项目进展顺利的所有方法:)您应该在日历上调用数据绑定1:)
您应该调用日历上的数据绑定1:)
我单击按钮时正在考虑ViewState,但我不知道如何修复:我猜问题是日历在OnClick代码执行之前呈现数据,因此您看不到更改?如果是这样,只需调用
Calendar1.DataBind()代码>在按钮单击事件处理程序中。否将asp:按钮从FormView放到Onload到Page_Load并放到DataBind();现在加载页面效果很好干杯,请将此作为新答案添加并接受,以便其他人知道问题的解决方法。我单击按钮时正在考虑ViewState,但我不知道如何修复:PI猜测问题是日历在OnClick代码执行之前呈现数据,因此您看不到更改?如果是这样,只需调用Calendar1.DataBind()代码>在按钮单击事件处理程序中。否将asp:按钮从FormView放到Onload到Page_Load并放到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);
}
Calendar1.DataBind();