开发者

How to refresh page after Button submit to Direct SQL?

I have a question about my current project Calendar / event planner:

I have an OnClick submit to a direct database without stored procedures. The idea is that the page or cell of the day in my calendar needs to be directly showed into that day / cell.

Now I need to click on the day number to see it (it's stored in the database) does someone have any idea because I have tried with JavaScript:

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

Not in a button because I need that button for another Onclick event. Thanks for advice. :)

My current code behind is:

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

The fix i have found is as follow not The Calender1.DataBind(); but here we go

   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 all for helping the project is going well :)


You should call DataBind on the Calendar1 :)

Calendar1.DataBind();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜