Check to see if a string is empty

There are several ways to check a string to see if it’s empty.  However, you should try to always use the following method.  It’s faster, and uses less resources.  This may seem like a minimal piece of code – but if you were checking strings through out your application, it all adds up in the…


Adding a ListItem to a dynamic dropdown list

If you manually add a listitem to a dynamic dropdown list, ensure that you set the appenddatabounditems attribute to true.  If you don’t, the dynamic items will overwrite the ones you manually added. <asp:dropdownlist id="DevelopmentCycleDropDown" runat="server" appenddatabounditems="True" datasourceid="ObjectDataSourceDevelopmentCycle"         datatextfield="Name" datavaluefield="Id" selectedvalue='<%# Bind(’DevelopmentCycleId’) %>’>             <asp:listitem selected="True" text="Select Cycle" value="0"></asp:listitem>         </asp:dropdownlist>


Including a file in a Web Deployment Project

Argh Argh.  I’m precompiling a website (msbuild) and then building an installer for deploying it.  For the build, I’m use WDP.  However; for whatever silly reason Visual Studio ignores file types of .lic   So I have a license file that won’t get built, and to be honest I don’t want to manually add it to…


Activating ActiveX Controls

Since Microsoft has released their new security around ActiveX Controls, you may have noticed that Internet Explorer isn’t too friendly torwards Flash anymore. For more detailed information on the new security and how Control Activation works here, Activating ActiveX Controls. Here is a quick example of how you can load a flash file ‘externally’ so…


Allow Only Numbers In A String - C#

Often you may have user input that needs to only be numbers, and the input doesn’t allow characters.  There is javascript that you can put on the front end to limit what keystrokes can be made in an input field; however, there are still ways around it.  Here’s a good filter method that you can…


Difference between two Dates

Here’s some useful code if you need to know how much time has elapsed between two days.         DateTime oldDate = new DateTime(2005, 7, 31);         DateTime newDate = DateTime.Now;           // Difference in days, hours, and minutes.         TimeSpan timeSpan = newDate – oldDate;           // determine how many days are in…


Regular Expression Library

Regular Expressions.  Joy oh Joy.  Here’s a great site to help ease the pain in writing one: Regular Expression Library.  They have over a thousand indexed expressions and it even has an online tool to help you test expressions: I used it to help me find a good expression for validating email addresses.  Check…


Use an Image in a HyperLinkColumn

I’ve seen a lot of posts on boards of people inquiring how to utilize an image in a hyperlinkcolumn.  I found those posts, because I was trying to do the same thing.  In my codebehind, I had some custom things going on for the link, and really didn’t feel like comprimising any of that by…


Formatting Strings in a DataGrid

In my opinion, one of the coolest .net controls is the DataGrid.  There is sooo much you can do with this puppy.  One of the things I like most about it is how you can choose to control or not control how data is rendered.  Which brings me to the topic of this post, how…