views:

185

answers:

4

I've got an ASP.NET application that shows grades for different kinds of students. Some students have a self-paced course that doesn't include late penalties and quizzes, and others have a standard classroom course that does.

So, when displaying a student's grade, I determine which category that student falls in, and then render the grade appropriately.

Right now I do this with conditional statements, but I thought about making each case into an ascx file (i.e. one ascx with a gridView for self-paced, and one with a gridView for classroom, each of which calls data population methods in my data access class).

I may need to re-use this functionality elsewhere in the app, to show grades on different pages, so some kind of custom control seems warranted.

Is this approach feasible?

A: 

This approach sounds good to me - controls are designed to help you reuse code. I think a set of UserControls would work just fine here.

Andrew Hare
A: 

This approach is definitely feasible, and it makes it easy to change if you want to modify the way the HTML is displayed at a later time (new styles, etc.). I would say ASCX is a good approach.

Brandon Montgomery
A: 

Make sure you are adequately separating your calculation logic from the display. I would use a class to actually determine the grades (perhaps multiple classes with a nice inheritance tree) to actually do the match, and the just render appropriately in your user control.

If you have multiple classes (or some property for determining what type a particular isntance is) you could also then easily create a factory to instantiate user controls for you where you will get the correct user control type, based on the calculation passed.

Jason Coyne
Right now my calculation logic works with a datatable object returned from the database and sends a datatable to the front end as the source for the gridView. All calculations are already done by the time the second datatable gets to the front end.
Caveatrob
A: 

Here's how I understand your app:

  1. You have students that are registered for courses.
  2. Students can be standard or self-paced.
  3. The grading method per course is different for different types of students.
  4. You need a way to display the correct grade based on the student's type.

I would think you could get by with a single control for displaying grades but would definitely make sure to separate your logic. Maybe something like:

public class Student{
   public GradingType Type {get;set;}
   public List<Course> RegisteredCourses{get;set;}
   //etc...
}

public class Course{
   //etc...
}

public static class GradeCalculator{
   public static CalculateStudentGrade(Student student, Course course){
      //grade logic...
   }

}
Chuck