Alex Hodge
Mid-Term Extra Credit Correction:
1.) I assume that I missed points on the header label because I did not update the text in the header
label using the C# code behind but rather used the GUI to insert the data.
The code to correct the problem would reside in the MidterExam.Master.cs file in between the
brackets for the Page_Load method. it should read PageTitle.Text = "Alex's Midterm Exam"; which
when viewed in the browser shows the correct text.
2.) I misunderstood how the label in the footer date was supposed to be set up and spend most of
my time trying to figure out how to have all the text in the same variable as the date time information.
When I got stumped I moved on hoping to come back to it later on during the test. I also tried to use
the GetTime() method to get the time and not the DateTime method this caused some problems
because it is not as clean to use the getTime method.
The code to correct the problem begins in the footer div tag where the footerdate information
will be. I applied the following tag and control to set up were the text and then label box would be for
the Date information. <div>
Page Loaded at <asp:Label runat=server CssClass=footer_date
ID=FooterDate onload="FooterDate_PageLoad"></asp:Label>
</div>
I then used the page_load property of the label control to create the following method to grab the date,
format it and push it into the label.
protected void FooterDate_PageLoad(object sender, EventArgs e)
{
string TodaysDate;
TodaysDate = DateTime.Now.ToString("MM-dd-yyyy");
FooterDate.Text = TodaysDate;
3.) I made the mistake of not having my homework project printed out and ready to copy from
when I got to sections where a simple copy and paste would have corrected the entire problem. I did
not put a "~" in front of the defaultredirect tag so it would have had trouble finding the pages if it was
far enough into the directory tree. In the 404 tag I did not use the ~ marker again to tell the tag to go
the root directory first before looking for the error page.
The correct code to accomplish this in the web config file should have been
<customErrors mode="On" defaultRedirect="~/AppErrors/ErrorUndefined.aspx">
<error statusCode="404" redirect="~/AppErrors/PageMissing.aspx"/>
</customErrors>
4.) The mistake I made at this point was not adding the "Please Select" at the zero position of the
drop down list. I understood that it could be done by adding it into the table but I could not remember
how to append it as a list item.
To address this in the source code of the drop down box I added the command
AppendDataBoundItems and set it equal to true. I then added a asp:listitem control to
add in a new list item to the drop down box. since it is not bound to the database it
would show up first in the list in the zero position.
<asp:ListItem Text="Please Select" Value="null" />
I set the value of this field to null so that I could later used validation to make sure
the user had selected something from the field.
5/6/7.) If I understand what happened correctly when I created the drop down box I
chose the correct data base and set the values and names that would be displayed
correctly, but when I created the check box field I used the same data source so instead
of having the correct query it was overwrote the query for the drop down list and this
caused the filtering and formatting to be incorrect.
To correct this I would apply a second SqlData Source to draw the check box query
against and leave the first data source tied to the drop down list with the correct
query.
By adding this data source for the check box list to pull from <asp:SqlDataSource
ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:MidtermCS %>"
SelectCommand="SELECT DISTINCT residence FROM rich_people WHERE (rank <= 10)
ORDER BY residence">
</asp:SqlDataSource>
and removing all the other headings from the select field except residences so it would only return
unique entries this corrects the issue of showing duplicate cities.
I also changed the Query in the first data source that is tied to the drop down box to:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MidtermCS %>"
SelectCommand="SELECT rich_id, name FROM rich_people WHERE (age <= 50) ORDER
BY name">
</asp:SqlDataSource>
Which by doing so reapplied the filtering for age and the ordering by names portion back in.
8. I had already placed a compare valuator on to the drop down menu but had time was called before I
could set the parameters for the control. I had spent too much time trying to make the set the correct
date in the initial portion of the master page and ran out of time working on the last few items of the
exam.
In order to make sure that the user selected a name I added the following compare validation
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="You must select a name from the list!"
ValueToCompare="Please Select" Operator="NotEqual"></asp:CompareValidator>
This checked the dropdownlist to see if it was set on the "Please Select" option and if so tripped the
validation.
9/10. I had not attempted this part of the exam when time was called.
In order to make the results appear for both the residences and the names I first added two
panel tags one around the dropdown list and check boxes, and the other with the results information
text and labels.
<asp:Panel ID="Questions" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="rich_id"
AppendDataBoundItems="true" >
<asp:ListItem Text="Please Select" Value="Please Select" />
</asp:DropDownList>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="You must select a name from the list!"
ValueToCompare="Please Select" Operator="NotEqual"></asp:CompareValidator>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MidtermCS %>"
SelectCommand="SELECT rich_id, name FROM rich_people WHERE (age <= 50) ORDER
BY name">
</asp:SqlDataSource>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="residence"
DataValueField="residence">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:MidtermCS %>"
SelectCommand="SELECT DISTINCT residence FROM rich_people WHERE (rank <= 10)
ORDER BY residence">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Submit Selections!" />
</asp:Panel>
<asp:Panel ID="Anwsers" runat="server">
You selected the following:<br />
<br />
The name you selected was:<asp:Label ID="lblName" runat="server"></asp:Label>
<br />
<br />
The residence(s) you selected are:
<asp:Label ID="lblCity" runat="server"></asp:Label>
</asp:Panel>
Once these panels were added and labels added I went to the code behind and added an if/else
statement that would set visibility for the panels depending on whether the page had posted back or
not. If it had not they questions panel would display if it had then the answers panel would display.
//Determine if page has been posted back
if (!IsPostBack)//submit button has been pressed
{
//Toggle panel visibility
Questions.Visible = true;
Anwsers.Visible = false;
else
{
//Toggle panel visibility
Questions.Visible = false;
Anwsers.Visible = true;
lblName.Text = DropDownList1.SelectedItem.Text;
//get values from checkboxlist
String residenceList = "";
//loop through checkboxes and determine which ones were selected
foreach (ListItem li in CheckBoxList1.Items)
{
//If selected append to residenceList string object
if (li.Selected)
{
residenceList += li.Value + "; ";
}
else
{
residenceList = "No residences were selected!";
}
lblCity.Text = residenceList;
}
At the end of the else statement I set the labels that held the results information to the correct , but I
had to use the selectedItem command and set it to text to get the system to return the name field and
not the rich_ID to the label. On the check box I created a string variable to hold the information's from
the check box list if there was more than one checked. I used a foreach loop to step through each item
of the check box and see if it had been selected. If it had I appended it to the String variable I created
and then added punctuation. I used an else statement after this that if nothing was selected to return
the correct text. In the case the message that No residences were selected.
From what I could tell from the exam and from the grading sheet these were the ten line items I missed
points on. If there are any questions or if you would like to see the revised project let me know and I
will send a copy of it too you.