Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Student class representing a real-life student.
- */
- public class Student
- {
- /* Override default constructor */
- public Student(string first, string last, string studentid, string program, string option)
- {
- FName = first;
- LName = last;
- STID = studentid;
- Program = program;
- Option = option;
- }
- /* Property for the student's first name */
- public string FName
- {
- set; get;
- }
- /* Property for the student's last name */
- public string LName
- {
- set; get;
- }
- /* Property for the student ID */
- public string STID
- {
- set; get;
- }
- /* Property for the program of study */
- public string Program
- {
- set; get;
- }
- /* Property for the option within the program of study */
- public string Option
- {
- set; get;
- }
- }
- /* Class for the web form UI */
- public partial class _Default : System.Web.UI.Page
- {
- /* List of students to be displayed in the repeater control */
- private List<Student> myStudents;
- protected void Page_Load(object sender, EventArgs e)
- {
- myStudents = new List<Student>();
- /* Check postback value when the page loads - this is the first time */
- if (IsPostBack == false)
- {
- /* Bind the Collection to the Repeater control */
- Label1.Text = "" + myStudents.Count;
- Repeater1.DataSource = myStudents;
- Repeater1.DataBind();
- }
- }
- /*
- * Submit button clicked to submit the form.
- */
- protected void Button2_Click(object sender, EventArgs e)
- {
- /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
- if(Page.IsValid) {
- /*if its valid then create a new student object to put into the list of students
- get the data from POST*/
- myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));
- Label1.Text = "" + myStudents.Count;
- }
- }
- }
- <asp:Repeater ID="Repeater1" runat="server">
- <HeaderTemplate>
- <table border="1">
- <tr>
- <td><b>First Name</b></td>
- <td><b>Last Name</b></td>
- <td><b>Student ID</b></td>
- <td><b>Program</b></td>
- <td><b>Option</b></td>
- </tr>
- </HeaderTemplate>
- <ItemTemplate>
- <tr>
- <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
- </tr>
- </ItemTemplate>
- <AlternatingItemTemplate>
- <tr bgcolor="#e8e8e8">
- <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
- <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
- </tr>
- </AlternatingItemTemplate>
- <SeparatorTemplate>
- <tr>
- <td colspan="5"><hr /></td>
- </tr>
- </SeparatorTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- /* Class for the web form UI */
- public partial class _Default : System.Web.UI.Page
- {
- /* List of students to be displayed in the repeater control */
- private List<Student> myStudents = new List<Student>();
- protected void Page_Load(object sender, EventArgs e){
- /* Check postback value when the page loads - this is the first time */
- if (IsPostBack == false){
- this.bindRepeater();
- }
- }
- private void bindRepeater(){
- /* Bind the Collection to the Repeater control */
- Repeater1.DataSource = myStudents;
- Repeater1.DataBind();
- Label1.Text = "" + myStudents.Count;
- }
- /*
- * Submit button clicked to submit the form.
- */
- protected void Button2_Click(object sender, EventArgs e)
- {
- /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
- if(Page.IsValid) {
- /*if its valid then create a new student object to put into the list of students
- get the data from POST*/
- myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));
- this.bindRepeater();
- }
- }
- }
- Repeater1.DataBind();
Add Comment
Please, Sign In to add comment