Esempio n. 1
0
            public static List <DbEntities.Session> LoadSession(ref DropDownList cmbSession, int academicYearId, int selectedValue
                                                                , bool includeAllField = false, bool includeNoneField = false, bool includeEmptyField = false, bool selectActiveSession = false)
            {
                cmbSession.DataTextField  = "Name";
                cmbSession.DataValueField = "Id";
                using (var helper = new DbHelper.AcademicYear())
                {
                    var cats = helper.GetTopSessionListForAcademicYear(academicYearId);
                    if (includeNoneField)
                    {
                        cats.Insert(0, new DbEntities.Session()
                        {
                            Id = 0, Name = "None"
                        });
                    }
                    if (cats.Count > 0)
                    {
                        if (includeAllField)
                        {
                            cats.Add(new DbEntities.Session()
                            {
                                Id   = 0,
                                Name = "All"
                            });
                        }
                        else
                        if (includeEmptyField)
                        {
                            cats.Insert(0, new DbEntities.Session()
                            {
                                Id   = 0,
                                Name = ""
                            });
                        }
                    }

                    cmbSession.DataSource = cats;
                    cmbSession.DataBind();

                    if (selectedValue >= 0)
                    {
                        var index = cats.IndexOf(cats.First(x => x.Id == selectedValue));
                        if (index >= 0)
                        {
                            cmbSession.SelectedIndex = index;
                        }
                    }
                    else if (selectActiveSession)
                    {
                        var index = cats.IndexOf(cats.First(x => x.IsActive));
                        if (index >= 0)
                        {
                            cmbSession.SelectedIndex = index;
                        }
                    }
                    return(cats.ToList());
                }
            }
Esempio n. 2
0
 public static List <DbEntities.AcademicYear> LoadAcademicYear(
     ref DropDownList cmbAcademicYear, int schoolId
     , int selectedValue = 0)
 {
     cmbAcademicYear.DataTextField  = "Name";
     cmbAcademicYear.DataValueField = "Id";
     using (var helper = new DbHelper.AcademicYear())
     {
         var acaYear = helper.ListAcademicYears(schoolId);
         if (acaYear.Count > 0)
         {
             acaYear.Insert(0, new DbEntities.AcademicYear()
             {
                 Id = 0, Name = "  Select  "
             });
         }
         cmbAcademicYear.DataSource = acaYear;
         cmbAcademicYear.DataBind();
         if (selectedValue > 0)
         {
             var index = acaYear.IndexOf(acaYear.First(x => x.Id == selectedValue));
             if (index >= 0)
             {
                 cmbAcademicYear.SelectedIndex = index;
             }
         }
         else
         {
             try
             {
                 var index = acaYear.IndexOf(acaYear.First(x => x.IsActive));
                 if (index >= 0)
                 {
                     cmbAcademicYear.SelectedIndex = index;
                 }
             }
             catch { }
         }
         return(acaYear.ToList());
     }
 }