Guest User

Untitled

a guest
Jan 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. /*
  2. * Student class representing a real-life student.
  3. */
  4. public class Student
  5. {
  6.  
  7. /* Override default constructor */
  8. public Student(string first, string last, string studentid, string program, string option)
  9. {
  10. FName = first;
  11. LName = last;
  12. STID = studentid;
  13. Program = program;
  14. Option = option;
  15. }
  16.  
  17. /* Property for the student's first name */
  18. public string FName
  19. {
  20. set; get;
  21. }
  22.  
  23. /* Property for the student's last name */
  24. public string LName
  25. {
  26. set; get;
  27. }
  28.  
  29. /* Property for the student ID */
  30. public string STID
  31. {
  32. set; get;
  33. }
  34.  
  35. /* Property for the program of study */
  36. public string Program
  37. {
  38. set; get;
  39. }
  40.  
  41. /* Property for the option within the program of study */
  42. public string Option
  43. {
  44. set; get;
  45. }
  46.  
  47. }
  48.  
  49. /* Class for the web form UI */
  50. public partial class _Default : System.Web.UI.Page
  51. {
  52.  
  53. /* List of students to be displayed in the repeater control */
  54. private List<Student> myStudents;
  55.  
  56. protected void Page_Load(object sender, EventArgs e)
  57. {
  58.  
  59. myStudents = new List<Student>();
  60.  
  61.  
  62.  
  63. /* Check postback value when the page loads - this is the first time */
  64. if (IsPostBack == false)
  65. {
  66. /* Bind the Collection to the Repeater control */
  67. Label1.Text = "" + myStudents.Count;
  68. Repeater1.DataSource = myStudents;
  69. Repeater1.DataBind();
  70. }
  71.  
  72.  
  73. }
  74.  
  75. /*
  76. * Submit button clicked to submit the form.
  77. */
  78. protected void Button2_Click(object sender, EventArgs e)
  79. {
  80.  
  81. /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
  82. if(Page.IsValid) {
  83.  
  84. /*if its valid then create a new student object to put into the list of students
  85. get the data from POST*/
  86. myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));
  87.  
  88. Label1.Text = "" + myStudents.Count;
  89.  
  90.  
  91. }
  92.  
  93. }
  94. }
  95.  
  96. <asp:Repeater ID="Repeater1" runat="server">
  97. <HeaderTemplate>
  98. <table border="1">
  99. <tr>
  100. <td><b>First Name</b></td>
  101. <td><b>Last Name</b></td>
  102. <td><b>Student ID</b></td>
  103. <td><b>Program</b></td>
  104. <td><b>Option</b></td>
  105. </tr>
  106. </HeaderTemplate>
  107.  
  108. <ItemTemplate>
  109. <tr>
  110. <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
  111. <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
  112. <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
  113. <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
  114. <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
  115. </tr>
  116. </ItemTemplate>
  117.  
  118. <AlternatingItemTemplate>
  119. <tr bgcolor="#e8e8e8">
  120. <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
  121. <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
  122. <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
  123. <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
  124. <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
  125. </tr>
  126. </AlternatingItemTemplate>
  127.  
  128. <SeparatorTemplate>
  129. <tr>
  130. <td colspan="5"><hr /></td>
  131. </tr>
  132. </SeparatorTemplate>
  133.  
  134. <FooterTemplate>
  135. </table>
  136. </FooterTemplate>
  137. </asp:Repeater>
  138.  
  139. /* Class for the web form UI */
  140. public partial class _Default : System.Web.UI.Page
  141. {
  142.  
  143. /* List of students to be displayed in the repeater control */
  144. private List<Student> myStudents = new List<Student>();
  145.  
  146. protected void Page_Load(object sender, EventArgs e){
  147.  
  148. /* Check postback value when the page loads - this is the first time */
  149. if (IsPostBack == false){
  150. this.bindRepeater();
  151. }
  152. }
  153.  
  154. private void bindRepeater(){
  155. /* Bind the Collection to the Repeater control */
  156. Repeater1.DataSource = myStudents;
  157. Repeater1.DataBind();
  158. Label1.Text = "" + myStudents.Count;
  159. }
  160.  
  161. /*
  162. * Submit button clicked to submit the form.
  163. */
  164. protected void Button2_Click(object sender, EventArgs e)
  165. {
  166.  
  167. /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
  168. if(Page.IsValid) {
  169.  
  170. /*if its valid then create a new student object to put into the list of students
  171. get the data from POST*/
  172. myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));
  173. this.bindRepeater();
  174.  
  175.  
  176. }
  177.  
  178. }
  179. }
  180.  
  181. Repeater1.DataBind();
Add Comment
Please, Sign In to add comment