title: Databinding DayPilot Calendar with value from database asp.net C#
body: <p>I using DayPilot Lite 3.1 from :</p>
  
  <p><a href="http://www.daypilot.org" rel="nofollow">http://www.daypilot.org</a></p>
  
  <p>Now I like to fill the calendar with value from the my sql database but I don't know how ?</p>
  
  <p>Can you help me, what I need to write in the protected DataTable getData()?</p>
  
  <p>Here is the code behind:</p>
  
  <pre><code>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;
          }
      }
  
  
  }  
  </code></pre>
  
  <p>Here is the code how was before I edit :</p>
  
  <pre><code>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;
  </code></pre>