Articles in this section
Category / Section

How to load holidays from database into Gantt

1 min read

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.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied