C# & VB.NET Coding Standards Guides

Clint Edmonson has released a some free C# and VB.NET Coding standards guides to the community to use.  For anyone who wants to download them they can be downloaded below

C# & VB.NET Coding Standards Guides

kick it on DotNetKicks.com

Posted on 12/27/2008 4:47:52 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: C# | VB.NET | Visual Studio | Programming

Tags: , , ,

Converting HTML Hex Color Codes to RGB in ASP.NET

This is another post for my own remembrance. While working with controls in ASP.NET most of the back colors use the RGB color references instead of allowing you to quickly plug in the Hexadecimal numbers to the control.  At first glance this looks to be a daunting task as there doesn’t appear to be a quick solution for this within the Color class in either VB.NET or C#. But the solution is pretty simple

VB.NET Example

  1: MyControl.BackColor = ColorTranslator.FromHtml("#FFFFFF")

C# Example

  1: MyControl.BackColor = ColorTranslator.FromHtml("#FFFFFF");

It actually becomes pretty easy after you find it.  There are some pretty elegant solutions to this problem on the NET but a lot of them don’t take advantage to what Microsoft has already built into the .NET Framework.

Technorati Tags: ,,,

Posted on 9/24/2008 9:03:25 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: ASP.NET | C# | Programming | VB.NET

Tags: , , ,

VB.NET Equivalent of C# typeof()

I’ve been slowly adding things that I run across that I need to remember to my blog so that I can find them at a later time. As well as allowing other people with the same issue to find a solution for themselves.

  1: typeof(Widget)

is the equivalent in VB.NET of

  1: GetType(Widget)

Now the next time I start looking for this I’ll have it on the blog and easily searchable.

del.icio.us Tags: ,,

Technorati Tags: ,,

kick it on DotNetKicks.com

Posted on 9/24/2008 8:19:36 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: C# | Programming | VB.NET

Tags: , ,

How to sort a DataTable

While working on one of my modules I had a request to be able to sort the items in my DataList alphabetically. This seemed to be a trivial thing as far as I was concerned so off I went.  I was using a DataTable to bind to the DataList control for viewing the links I was building.  So with a quick search on Google I came up with some sample code to give me the basics of what I wanted to accomplish.  So in the following I will present both a C# and VB version of the code for anyone to use in their applications.

VB.NET Version

   1:  Private Function AlphabeticSort(ByVal dtTable As DataTable, ByVal sortOrder As Integer) As DataTable
   2:      Dim dsSorted As New DataSet
   3:      Dim columnKey As String = "TabName"
   4:      Dim sortDirection As String = ""
   5:      Dim sortFormat As String = "{0} {1}"
   6:      Select Case sortOrder
   7:          Case 0
   8:              sortDirection = "ASC"
   9:          Case 1
  10:              sortDirection = "DESC"
  11:          Case Else
  12:              sortDirection = "ASC"
  13:      End Select
  14:      dtTable.DefaultView.Sort = String.Format(sortFormat, columnKey, sortDirection)
  15:      Return dtTable.DefaultView.Table
  16:  End Function

C# Version

   1:  private DataTable AlphabeticSort(DataTable dtTable, int sortOrder)
   2:  {
   3:      DataSet dsSorted = new DataSet();
   4:      string columnKey = "TabName";
   5:      string sortDirection = "";
   6:      string sortFormat = "{0} {1}";
   7:      switch(sortOrder)
   8:      {
   9:          case 0:
  10:              sortDirection = "ASC";
  11:              break;
  12:          case 1:
  13:              sortDirection = "DESC";
  14:              break;
  15:          default:
  16:              sortDirection = "ASC";
  17:              break;
  18:      }
  19:      dtTable.DefaultView.Sort = string.Format(sortFormat, columnKey, sortDirection);
  20:      return dtTable.DefaultView.Table;
  21:      }

As you can see the code is very familiar between the two.  This works excellent for doing an alphabetic sort and very fast as well.

Technorati Tags: , , ,

del.icio.us Tags: , , ,

kick it on DotNetKicks.com

Posted on 2/8/2008 11:50:12 PM by admin

Permalink | Comments (2) | Post RSSRSS comment feed |

Categories: ASP.NET | C# | Visual Studio | VB.NET

Tags: , , ,