开发者

Cant post result from partial class method into datagrid

开发者 https://www.devze.com 2023-03-09 20:24 出处:网络
I\'ve been given a few questions to answer for an interview prior to going to it. I\'ve been told to do as much research as I can and ask for answers where necessary. I\'ve tried everything I can to g

I've been given a few questions to answer for an interview prior to going to it. I've been told to do as much research as I can and ask for answers where necessary. I've tried everything I can to get this working but I am at a loss. I've never done C# coding until yesterday so this is a big step into the world of the unknown.

The question I've been given is Create a partial class for Course and add a property which only returns Students where their AverageSCore is greater than 70

Now a brief introduction to what I've been given. The program consists of 4 tables linked together. They are Courses, Students, Teachers and Departments. Each table is represented as an Entity Course, Student, Teacher and Department. The code is set out into a number of different pages and the results are displayed on the webage Courses.Aspx. Now I've added a gridview (GridView1) to display the results of each question to show that its working.

They want me to add a Course partial class to a page called PartialClasses.cs and display the results on Courses.Aspx. Now the code I've been given for each page is

Courses.Aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Code.Web;
using School.Code;

namespace School
{
    public partial class Courses : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
                                            }
        }

        public void LoadData()
        {

            IEnumerable<Course> courses = SchoolManager.GetAllCourses();

            //Bind list view with classes

        }

PartialClasses.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Metadata.Edm;
using System.Data.O开发者_StackOverflow社区bjects.DataClasses;
using System.Data.Objects;

namespace School.Code
{

    public partial class Teacher
    {
        public string FullName
        {
            get
            {
                return string.Format("{0} {1}", FirstName, LastName);
            }
        }
    }

    public partial class Student : SchoolManager
    {
        public string FullName
        {
            get
            {
                return string.Format("{0} {1}", FirstName, LastName);
            }
        }

}

Now I know that this would produce the correct results

using (SchoolEntities ctx = new SchoolEntities())
{
    var results = from b in ctx.Students
                  where b.AverageScore > 70
                  select b;
    Array newarray = results.ToArray();
}

But I don't know how I add this to the PartialClass.cs page and then get the results into the Courses.Aspx page. Can anyone give me an example of how this is done please?


Create Partial class for SchoolManager and add the last code snippet into it as readonly property or as a method, it is up to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消