Checking boxes in a C# ASP checkbox list using values from a database

Suppose you have an ASP checkbox list and you need to check the boxes using data returned from the information storage.

You have a couple of ways the data could have been stored. If each checkbox option is a separate field in the database, you could go with a simple loop, but if they have been stored in one field, you need to put some programming power into it.

Here’s a scenario. I have a “seasons” checklist. There are values stored in the db that the user selected. For example if they chose Summer and Fall, the db string “seasons” would contain “Summer Fall”.

<asp:CheckBoxList ID="CheckBoxListSeasons" runat="server">
 <asp:ListItem>Summer</asp:ListItem>
 <asp:ListItem>Fall</asp:ListItem>
 <asp:ListItem>Winter</asp:ListItem>
 <asp:ListItem>Spring</asp:ListItem>
 </asp:CheckBoxList>

In order to display the list with the Summer and Fall boxes checked, I would do this:

string seasons = "Summer Fall"
for (int i = 0; i < CheckBoxListSeasons.Items.Count; i++)
 {

if (seasons.Contains(CheckBoxListSeasons.Items[i].Value))
 {

CheckBoxListSeasons.Items[i].Selected = true;
 }
 } // end checkbox loop

 

 

 

Transformation Matrices

Rotate a figure 180 degrees around the origin:

From your original figure, just reverse the polarity of the ordered pairs.

Point A(x,y) will be Point a(-x, -y)

(-6,3) (-3,3) (-2,5) (-2,1) (-6,1) original
(6,-3) (3,-3) (2,-5) (2,-1) (6,-1) rotated 180 degrees around origin.

 

Reflect over y-axis

From the original, reverse the polarity of the x value. Point A(x,y) will become point a(-x,y)

(-6,3) (-3,3) (-2,5) (-2,1) (-6,1) original
(6,3) (3,3) (2,5) (2,1) (6,1) reflected over y axis

 

Rotate 90 degrees counter clockwise around origin

The new position of point M (h, k) will become M’ (k, -h)

 

 

SQL Select records by the hour or the half hour

Here is a handy SQL snippet to select records by the half hour in a certain date range.

SELECT DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0) as LoginHour, Count(*) as NumberOfUsers FROM[my_db].[dbo].[MyTable] WHERE [LoginTime] BETWEEN '{0} 00:00:00.00' AND '{0} 23:59:59.999' GROUP BY DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0) ORDER BY DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0)

The result set will look something like this:

 

Here is a code to select by the hour if you don’t need to go down to the half hour

SELECT datepart(HH, [LoginTime]) as LoginHour, Count(*) as NumberOfUsers

FROM[my_db].[dbo].[MyTable]

WHERE[LoginTime] BETWEEN '09/07/2017 00:00:00.00' AND dateadd(dd, 1, '10/20/2017 23:59:59.999')

GROUP BY datepart(HH, [LoginTime])

ORDER BY datepart(HH, [LoginTime])

 

And the result set will resemble this:

 

Here is a snipped to get a all records regardless of the date, and count by the half hour.

SELECT substring(CONVERT(VARCHAR, DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0), 108),0,6) as LoginHour, Count(*) as NumberOfUsers FROM[my_db].[dbo].[MyTable]  GROUP BY substring(CONVERT(VARCHAR, DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0), 108),0,6) ORDER BY substring(CONVERT(VARCHAR, DATEADD(mi, DATEDIFF(mi,0,[LoginTime])/30*30,0), 108),0,6)

SVC Fitness Center Use Reports

I was tasked to visualize the data from years of students using the Fitness Center. I worked with C# and SQL server to make make charts from the data. I used Visual Studio to create a  WebForms Application and deployed to IIS server. I was able to leverage active directory to provide integrated authentication to this resource.

Screen shot of hourly use report.
Screen shot of hourly use report.
Screen shot of quarterly use reports.
Screen shot of quarterly use reports.

Error checking with ASP classic VbScript

Here is a handy snippet for those rare occasions when you bother to error check.

 

If Err.Number <> 0 Then
subject = "Error creating early alert"
email_message = "There was the following error while creating an early alert record: " & Err.Number & " : " & Err.Description
sendEmail adminEmail, email_message, from_email, subject
End If

Can deliver a helpful error message such as:

There was the following error while creating a record: -2147217900 : Unclosed quotation mark after the character string ‘Failed a quiz/test’.

Prepend text “Select Value” to a databound dropdown list c#

You have a dropdown list, populated via sql data source, and you want it to have “Select a value” as the first selected option.

protected void DropDownList2_DataBound(object sender, EventArgs e)
        {
            DropDownList list = sender as DropDownList;
            if(list != null)
            {
                list.Items.Insert(0, "--Select Date--");
            }
        }