Posts

String.Empty vs ""

Image
So I've always heard you should use String.Empty vs "" the dreaded blank string in C#. So I decided to write a little test program to find out. It simply takes a string variable and assigns it to "" or String.Empty. I do this 1 million times each and time how many milliseconds it takes to do that assignment. My system is a p4 1.5 GHz RAM running .net 2.0. Source code can be sent upon request. The results are surprising and can be seen below. Other then the first run the String.Empty beat the "" by a few milliseconds. Hardly the creaming I've read about. But perhaps if you were doing some severe number crunching you would notice a difference. However this test is hardly definitive and should probably be run several more times and had the numbers aggregated. I've run the app a lot more since yesterday but only added one more screenshot. I may just post the screen UI and then keep track of the results in a spreadsheet or modify the app...

Nested Repeaters in ASP.NET

Ok so you may want to show some hierarchical data using repeaters. This means nesting a repeater in a repeater. This is fine but it takes some work in the code behind. First off create the main repeaters ItemDataBound event. In that event use the following code. I am old school so forgive me any syntax. For this code to work you must originally bind a DataSet to the parent repeater with a data relation connecting the parent/child tables. So somewhere (I do mine in page load) bind the entire dataset to the repeater: RepeaterCapabilities.DataSource = someDataSet; RepeaterCapabilities.DataBind(); Then put the following code in the repeaters ItemDataBound event protected void RepeaterCapabilities_ItemDataBound( object sender, RepeaterItemEventArgs e ) { Repeater rptActivities; DataRowView drv; // get the row behind the databind drv = e.Item.DataItem as DataRowView; if( drv != null ) { // get the nested repeater r...

Reading & writing connection strings to an app.config file in C# 2.0

Ok after working on this for a bit this morning I am sharing my experience with the world. I needed to read and write some connection strings found in an app.config file I was using in a small C# .NET 2.0 application. First you must have a reference to the System.configuration dll in your project and use the System.Configuration namespace in any C# files you want to do this stuff in. This sample assumes you have your connection strings in a connectionString section of an app.config file. Reading the connection string: ConfigurationManager.ConnectionStrings["Connection Name"].ConnectionString Writing the connection string: // get the config file for this application Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None ); // set the new values config.ConnectionStrings.ConnectionStrings["Connection Name"].ConnectionString = "Connection String Value"; // save and refresh the config file config.Save( Confi...

Javascript numeric only text box

So working on an asp.net page I found I needed a numeric only text box that allowed numbers from 0-100 with no decimals. I found a range validator would do most of the work but I wanted to keep users from typing in bad values. So after some searching I found javascript has a good solution. I like whitespace so shrink if you're one of those white space freaks. Update: someone was kind enough to point out an error in my JS! So I went through and made sure it works. And it did need a minor tweak to be correct. So thanks to the poster the corrected script and usage are below. Update Again: This is the new and improved function to allow for the tab key to tab out of the text box. IE allows this by default however Firefox really tightens down the text box and doesn't allow anything you don't specify. So I had to add the tab key press. I also cleaned up the code so it isn't a huge chunk of if blocks and is now much more succinct. Please feel free to test and us...

Welcome jrl-software

Well the end has started. I finally got jrl-software.com up and running. Clickity Click The main reason is to pimp my recently released utility called filesort. It sorts a file alphabetically in a pretty quick amount of time. So check out the site and send me feedback!

Convert HTML color to System.Drawing.Color

Ok so I have an HTML color I need to use in an asp.net web app. Problem is most of the asp.net controls use System.Drawing.Color. So I can't just go TextControl.BackColor = "FFFFFF"; or whatever you have to convert the HTML to a System.Drawing.Color like so: TextControl.BackColor = System.Drawing.ColorTranslator.FromHtml("FFFFFF"); And voila! HTML colors are now System.Drawing.Colors

Task bar shuffle

I've always hated I couldn't move programs around in the taskbar. Well some dude has come up with the answer! Praise Jebus! Clicky Clicky