我从以下位置使用 DayPilot Lite 3.1:
现在我喜欢用我的 sql 数据库中的值填充日历,但我不知道怎么做?
你能帮我吗,我需要在受保护的 DataTable getData() 中写什么?
这是后面的代码:
namespace Rezervacii{
public partial class Events : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DayPilotCalendar1.StartDate = firstDayOfWeek(DateTime.Now, DayOfWeek.Sunday);
DayPilotCalendar1.DataSource = getData();
DataBind();
}
}
protected DataTable getData()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Korisnik;Integrated Security=True";
SqlDataAdapter da = new SqlDataAdapter("SELECT [id], [name], [startevent], [endevent] FROM [Event] WHERE id=@id , name=@name, startevent=@startevent, endevent=@endevent", con);
DataTable dt;
dt = new DataTable();
da.Fill(dt);
return dt;
}
private static DateTime firstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}
protected void DayPilotCalendar1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e)
{
string color = e.DataItem["color"] as string;
if (!String.IsNullOrEmpty(color))
{
e.DurationBarColor = color;
}
}
}
这是我编辑之前的代码:
protected DataTable getData()
{
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("color", typeof (string));
DataRow dr;
dr = dt.NewRow();
dr["id"] = 0;
dr["start"] = Convert.ToDateTime("15:50");
dr["end"] = Convert.ToDateTime("15:55");
dr["name"] = "Event 1";
dt.Rows.Add(dr);
return dt;