Test Menu

  • Commentary
  • Deals
  • Coupons

Oct 5, 2011

Convert Delimited List to List(of String)

Converting a Pipe Delimited List of Values into a Generic List (of String)

Sometimes it's helpful to convert data into a different format before further processing. In this case, converting the delimited list to a generic list of string will make it more friendly for loops.


    Public Shared Function CreateSupplierList(strSupplierPipedList As String) As List(Of String)

        Try
            ' split the pipe delimited list into an array and then add to a generic list
            Dim strSupplierList() As String = strSupplierPipedList.Split("|")

            Dim lst As New List(Of String)

            For intCount = 0 To strSupplierList.Length - 1
                lst.Add(strSupplierList(intCount))
            Next

            Return lst

        Catch ex As Exception
            Return New List(Of String)
        End Try

    End Function

Aug 18, 2011

Using Lists Instead of Paragraph Tags for Lists of Links


Instead of using multiple <p> tags for lists of links use <ul> and <li> tags!

Recently, I was revising and old web page and found some quick and easy improvements to make.

This is better J

<ul class="ul">
<li><a href="page1.htm">Page 1</a> </li>
<li><a href="page2.htm">Page 2</a> </li>
<li><a href="page4.htm">Page 3</a> </li>
<li><a href="page4.htm">Page 4</a> </li>
</ul>



Than this L

<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page1.htm">Page 1</a></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page2.htm">Page 2</a></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><b><a href="page3.htm">Page 3</a></b></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page4.htm">Page 4</a></font>
</p>

Jun 30, 2011

Force Compatibility Mode in Meta Tag

Here's a nice easy way to force the page to be loaded in IE compatibility mode.

<meta http-equiv="X-UA-Compatible" content="IE=7" />

Jun 21, 2011

Calling Existing Javascript from Code Behind

Notes on how to call an existing javascript function from the code-behind.  The "confirmDelete" function below calls a jQuery dialog that will be used to delete records from a datalist.  I'm running this script from the code behind because I want to populated the dialog with values from the datalist record to allow the user to view the data they are about to delete.  The code at the bottom contained in the datalist ItemCommand method and runs when the e.CommandName = "Delete".


ASPX


<script type="text/javascript">
        // increase the default animation speed to exaggerate the effect
        $.fx.speeds._default = 400;
        function confirmDelete() {


            var dlgeditproduct = $(".deleteconfirmdiv").dialog({
                modal: true,
                width: 750,
                height: 450,
                autoOpen: false,
                title: "Are you sure you want to delete this News Release?",
                hide: "explode"
            });


            $(".deleteconfirmdiv").dialog("open");


            dlgeditproduct.parent().appendTo(jQuery("form:first"));


        };
</script>



VB


 Page.ClientScript.RegisterStartupScript(Me.GetType(), "confirmdelete", "confirmDelete();", True)

Jun 20, 2011

ASP.NET - Read Content of File from FileUpload Control

' this code would be on the page or control and be called on some kind of action (click etc)
Dim strFileContent As String = ReadFileToString(FileUpload.PostedFile.InputStream)


' function to return file content as string from the Stream (in this case is was an html file)
Private Shared Function ReadFileToString(ByVal streamFileContent As System.IO.Stream) As String


Try


  ' read the contents of the file into a string
  Dim strFileContent As String = String.Empty


  Using sr As IO.StreamReader = New IO.StreamReader(streamFileContent)


    strFileContent = sr.ReadToEnd


  End Using


  Return strFileContent


  Catch ex As Exception
    Utilities.LogError(ex, "ParseHTML.vb.ReadFileToString")
    Return String.Empty
  End Try


End Function

May 23, 2011

Linq - Select TOP Example

An example of a linq statement that takes the first three items in the collection of listitems.  I used this example when I was synchronizing different tabs of a website that each had listboxes.  One of the tabs had a limit of three selected items:

Protected Sub Page_ListSync(ByVal lstSelected As List(Of ListItem), ByVal lstAvailable As List(Of ListItem))

        Try

            '  just take the first three from selected
            Dim liCollection = From li In lstSelected Select li Take 3

            lstSelected = liCollection.ToList()

            SRBC.RWQMN.SyncListboxes(lstSelectedStations, lstSelected, lstAvailableStations, lstAvailable)

        Catch ex As Exception
            SRBC.SRBCErrorLogging.LogError(ex, "ctrlStatistics.Page_ListSync")
        End Try

End Sub

May 4, 2011

SQL - Keep Functions Out of the Where Clause

Taking functions out of the where clause improved stored procedure performance by 2300%.  In my original stored procedure with two functions in the where clause it used to take 46 seconds to complete, but by replacing the functions with the raw data value that they return, the time was reduced to just 2 seconds

Slow:


SELECT MAX(Temperature) 
FROM #tblStationStatistics 
WHERE StationID = A.StationID
    AND Temperature BETWEEN dbo.fnGetMinThreshold('Temperature') AND dbo.fnGetMaxThreshold('Temperature')


Fast:


SELECT MAX(Temperature) 
FROM #tblStationStatistics 
WHERE StationID = A.StationID
    AND Temperature BETWEEN -10 AND 60