Test Menu

  • Commentary
  • Deals
  • Coupons

Nov 29, 2011

Averages with Linq

Here are two different ways to get the average using Linq.  These examples use a generic list of a class that has a Temperature  property:


Dim avgTemperature = (From c In lst Where c.Temperature IsNot Nothing Select c.Temperature).Average()


Dim avgTemperature = From t In lst Where t.Temperature IsNot Nothing Aggregate Temperature In lst Into Average(t.Temperature)

Nov 28, 2011

Concatenating Static Text to an Eval Expression

This wasn't obvious to me even though it seemed basic.  Full credit goes to the original post on stackoverflow.

I was using a datalist and wanted to concatenate the text "Collection Type: " before the Eval expression.  The only solution I could find was to use a format string.  I favored this solution instead of using the code-behind.

<asp:Label ID="CollectionTypeLabel" runat="server" text='<%#DataBinder.Eval(Container.DataItem, "CollectionType", "Collection Type: {0}")%>' />

Nov 22, 2011

Databound Checklist - Check All by Default


The following code shows an easy way to loop through the list of checkboxes and select each one:


''' <summary>
''' checks all of the checkboxes by default
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub chkListParameterSelections_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkListParameterSelections.DataBound


        Try


            For Each li As ListItem In chkListParameterSelections.Items
                li.Selected = True
            Next


        Catch ex As Exception
            ErrorLogging.LogError(ex, "ctrlStatistics.chkListParameters_DataBound")
        End Try


End Sub

Nov 10, 2011

CSS Problem After IFrame Loads

Problem: The CSS is breaking in a web page that includes an iframe in IE8 when the content of the iframe loads.  The page works fine in firefox and chrome.  Other pages without the iframe that use the same CSS file don't have the problem.

Fix: This tag was in the head: 
<meta http-equiv="X-UA-Compatible" content="IE=8" />

It was changed to: 
<meta http-equiv="X-UA-Compatible" content="IE=7" />

Nov 4, 2011

Clear All Textboxes on a Web Form

For Each ctrl As Control In Form.Controls
    If ctrl.GetType.Name = "TextBox" Then 
        Dim tb As TextBox = ctrl tb.Text = String.Empty
    End If 
 Next