1 / 17

Summary

Summary. Reviewing work from week one. Summary. We will review the work done this week. Lecture One introduced the Editor and CSS Lecture Two showed how to create controls Lecture Three was about tables and css. Lecture Four concerned data. Lecture Five creates a test. VS Editor.

moanna
Download Presentation

Summary

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Summary Reviewing work from week one.

  2. Lecture 5: Review Summary • We will review the work done this week. • Lecture One introduced the Editor and CSS • Lecture Two showed how to create controls • Lecture Three was about tables and css. • Lecture Four concerned data. • Lecture Five creates a test.

  3. Lecture 5: Review VS Editor • The Visual Studio Editor allow you to design a web page. • The elements used include: • Panel

  4. Lecture 5: Review Generate • You can use C# to create controls. • You can change the properties of the controls. • You must add the new control to the page. • Some controls may be added to Controls • Some controls must be added to form1.Controls

  5. Lecture 5: Review Styling • You can change the style of controls as you create them. • Usually it is better to set CSS styles and rely on an external style sheet. • This means that the “look and feel” design work may be done after the coding is complete.

  6. Lecture 5: Review Events • Event only take place at the server. • You can capture OnClick events – at this time you can interrogate the value of various controls. • The value of the control is usually a string – you have to convert the string into whatever value you need.

  7. Lecture 5: Review Data - Lists • You can store data in an Array or in a SortedList. • An Array is simple and quick to create: String [] a = new String[] {"one", "two"}; • A SortedList is more powerful, you can access items using Strings and the key. • There are other structures – but SortedList is one of the best.

  8. Lecture 5: Review Finding Controls • Sometimes you need to run over all of the controls on the page. • You may need to look in the Controls structure • You may need to look into the form1.Controls structure. • Usually only some of the controls in the lists are the ones you want.

  9. Lecture 5: Review Testing the Type • You can use if (c is Panel) to test if the controls c is a Panel: for (inti = 0; i < form1.Controls.Count; i++) { if (form1.Controls[i] is Panel) { Panel p = (Panel)form1.Controls[i]; foreach (Control c in p.Controls) if (c is RadioButtonList) { RadioButtonListrbl = (RadioButtonList)c; if (rbl.Text == "1") score++; } } }

  10. Lecture 5: Review Multiple Choice • You can create a multiple choice quiz. • The questions and responses are coded as data. • The system can calculate the user’s score. • You can use a Class to represent a single question.

  11. Lecture 5: Review Question Class public class Question { public String questionText; public String[] distractors; public int correct; public Question(String questionText, String[] distractors, int correct) { this.questionText = questionText; this.correct = correct; this.distractors = distractors; } }

  12. Lecture 5: Review A List of Questions Question[] qList = { new Question( "Which property of Button would you change text color?", new String[]{"Color","BackgroundColor","Left","Top","Style"}, 0) ,new Question( "How do you make the cell td span two columns.", new String[]{"td.RowSpan = 2;","td.ColumnSpan = 2;", "td.ColumnSpan(2);", "td.Column.Span = 2; ", "ColumnSpan(td,2);"}, 1) };

  13. Lecture 5: Review Display a Question • We can display a question in a Panel. The ToPanel method of Question returns a Panel. public Panel ToPanel() { Panel p = new Panel(); Label q = new Label(); q.Text = this.questionText; p.Controls.Add(q); RadioButtonListrbl = new RadioButtonList(); for (inti = 0; i < distractors.Count(); i++) rbl.Items.Add(distractors[i]); p.Controls.Add(rbl); return p; }

  14. Lecture 5: Review Scoring • To score the test we need to “traverse” the list of radio buttons. • But... The RadioButtonList control has no record of the correct answer. • Controls such as Radio button items and DropListItems can have two values: • Text – the users see this value • Value – this is returned to the programmer.

  15. Lecture 5: Review Setting the value • We can set the value when we create the radio button item. • From ToPanel() delete this: rbl.Items.Add(distractors[i]); • Insert this: ListItem li = new ListItem(distractors[i], (i == correct) ? "1" : "0"); rbl.Items.Add(li);

  16. Lecture 5: Review Traversing the Page int score = 0; for (inti = 0; i < form1.Controls.Count; i++) if (form1.Controls[i] is Panel) { Panel p = (Panel)form1.Controls[i]; foreach (Control c in p.Controls) if (c is RadioButtonList) { RadioButtonListrbl = (RadioButtonList)c; if (rbl.Text == "1") score++; } }

  17. Lecture 5: Review Next Week • You will see the coursework. This is a longer task that you must complete on your own. • The lectures will include: • Reading from a database • Using JavaScript to have “client-side” processing.

More Related