)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load holidays from database into Gantt

Platform: ASP.NET MVC |
Control: Gantt |
Published Date: March 6, 2018 |
Last Revised Date: May 29, 2019

In Gantt, we can load holidays collection from database by passing holidays collections to view page by using ViewBag. The below code example shows how to load holidays from SQL database into Gantt.

C#

using Syncfusion.JavaScript.Models;
 
public ActionResult Index()
{
   ViewBag.holidays = GetHolidayData();
   //…
   return View();
}
public List<Holiday> GetHolidayData()
{
    List<Holiday> list = new List<Holiday>();
    SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString
    con.Open();
    using (con)
    {
       using (var command = con.CreateCommand())
       {
          command.CommandText = "SELECT * FROM holidayData";
          using (var reader = command.ExecuteReader())
          {
             var indexOfCol1 = reader.GetOrdinal("Day");
             var indexOfCol2 = reader.GetOrdinal("Background");
             var indexOfCol3 = reader.GetOrdinal("Label");                       
             while (reader.Read())
             {
                Holiday obj = new Holiday();
                obj.Day = reader.GetValue(indexOfCol1).ToString();
                obj.Background= reader.GetValue(indexOfCol2).ToString();
                obj.Label = reader.GetValue(indexOfCol3).ToString();                          
                list.Add(obj);
             }
             reader.Close();
          }
       }
       con.Close();
    }
    return list;
}

 

CSHTML

@(Html.EJ().Gantt("Gantt")
     //..
     .Holidays(ViewBag.holidays)
)
 
@(Html.EJ().ScriptManager())

 

Screenshot

Load holidays from database into Gantt.

 

Sample

A simple sample to load holidays from database is available here.

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon