/// <summary>
        /// When the page loads, all courses from the database are retrieved and displayed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            connectionString = ConfigurationManager.ConnectionStrings["flexiLearn"].ConnectionString;
            CourseDAO dao = new CourseDAO(connectionString);

            courses = dao.ReadAll();

            if (!IsPostBack)
            {
                GVCourses.DataSource = courses;
                GVCourses.DataBind();
            }
        }
Example #2
0
        private void BindGrid()
        {
            string    query = "select courseId ,courses.courseName , stream.streamName from courses inner join stream on courses.streamid = Stream.StreamId";
            DataTable dt    = c.getData(query);

            GVCourses.DataSource = dt;
            GVCourses.DataBind();

            if (dt.Rows.Count == 0)
            {
                noInfoAlert.Visible  = true;
                CoursesTable.Visible = false;
            }
            c.closeConn();
        }
        /// <summary>
        /// Displayed courses based on whatever inputs were given in filters
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnFilter_Click(object sender, EventArgs e)
        {
            // If there isn't a value for an input, adding dummy value that will match all courses
            string subject = (TxtSubject.Text != null) ? TxtSubject.Text.ToUpper() : "";
            string title   = (TxtTitle.Text != null) ? TxtTitle.Text.ToUpper() : "";

            // Needed to use TryParse because the number textboxes did not register as null even when empty
            float maxDuration;

            if (!float.TryParse(TxtMaxDuration.Text, out maxDuration))
            {
                maxDuration = 9999999;
            }
            ;
            float maxFee;

            if (!float.TryParse(TxtMaxFee.Text, out maxFee))
            {
                maxFee = 9999999;
            }
            ;

            List <Course> filtered = new List <Course>();

            // Add all courses that match all specifications
            foreach (Course course in courses)
            {
                if (course.Title.ToUpper().Contains(title) &&
                    course.Subject.ToUpper().Contains(subject) &&
                    course.Duration <= maxDuration &&
                    course.Fee <= maxFee)
                {
                    filtered.Add(course);
                }
            }

            // Display in GridView
            GVCourses.DataSource = filtered;
            GVCourses.DataBind();
        }
 /// <summary>
 /// Displays all courses in the database
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void BtnShowAll_Click(object sender, EventArgs e)
 {
     GVCourses.DataSource = courses;
     GVCourses.DataBind();
 }