views:

23

answers:

3

I'm working on a website that will allow instructors to report on the academic progress of students in their classes. I've got the website set up two primary pages: one with a user control that displays the classes (a GridView of basic class info with a child GridView in a template field that displays student names and checkboxes to select them -- called MiniStudents), and another with a user control that displays the selected students -- called FullStudents.

Although improbable, it's possible that an instructor could have the same student in two separate classes. I've already accounted for this in the current page setup -- the combination of student ID and class ID (class IDs change each quarter, for those thinking this will be an issue) form a unique key within the database. Recently, one of my users asked if I could break records out by classes on the page, so that instructors would be able easily recognize which class they're operating in.

So, my question is this: is it possible for me to dynamically add a column to the end of the class user control that would allow me to switch out MiniStudents for FullStudents?

If I've left out any important details or if anyone wants/needs code, please let me know.

A: 

You could add both, and hide one or the other.

Gabriel McAdams
A: 

You could use a multiview control to control which control is visible. Though I would be concerned about your viewstate size if you are loading all these controls simulantously. It sounds like there could be a lot of data and markup on the page.

ben f.
A: 

Try this:

//Under page_load
string path;
if(condition) path = "~/MiniStudents.ascx";
else path = "~/FullStudents.ascx";
Control userControl = this.LoadControl(path);
panel1.Controls.Add(userControl);

And if you have specific properties that you want to set before the usercontrol gets rendered then make them inherit a custom usercontrol class:

public class CustomControl : UserControl

public class MiniStudents : CustomControl
public class FullStudents : CustomControl

So then you can do this:

CustomControl userControl = (CustomControl)this.LoadControl(path);
userControl.UserId = userId;

I hope this helps!

Mouhannad