Tuesday, November 17, 2009

How do I loop through an enum

It is so easy to create enums and reuse them in multiple projects. You can use them in many places, one of the most common is to use them in drop down lists. Here, we'll show you how to create an enum, how to access the values using a foreach, then how to use an enum to fill a drop down list in c#.

First, make sure you have an enum defined:

public enum DaysOfTheWeek

{
 Monday,
 Tuesday,
 Wednesday,
 Thursday,
 Friday,
 Saturday,
 Sunday
}

Now that we have an enum, we would want to loop through it.

foreach(int value in System.Enum.GetValues(typeof(DaysOfTheWeek)))
{ 
  //To access the index (0,1,2,3,4,5,6) use the variable value stated above
  int intIndex = value;
 //To access the text of the index, get the names
  string strName = System.Enum.GetName(typeof(DaysOfTheWeek), value)
}
An example of filling a drop down list with enum values using the information above:

foreach(int value in System.Enum.GetValues(typeof(DaysOfTheWeek)))

{
  //Create the lineitem so we can add it to an existing dropdown
  ListItem liDay = new ListItem();

  //To access the index (0,1,2,3,4,5,6) use the variable value stated above

  liDay.Value = value.ToString();
 
  //To access the text of the index, get the names
  liDay.Text = System.Enum.GetName(typeof(DaysOfTheWeek), value)

  //Add it to the drop down
  ddlDaysOfTheWeek.Items.Add(liDay);

}







Wednesday, October 21, 2009

How do I add a theme to web.config file

In the web.config file, look for the pages tag under web.config. Within the pages tag add the attribute "theme", then type in the name of your theme.


Here's an example:



    

Saturday, August 29, 2009

Part Time Webmaster Launch

We've launched another site. It's called Parttimewebmaster.com. Here, we discuss a random listing of events and topics that may come up about websites. Feel free to comment, post, whatever. Right now, we have a forum area as well to review topics on open source software, hosting or search engines, etc.

Saturday, August 1, 2009

New Site launch! Jahbs.com

We have launched a new site called jahbs.com. Here you can network with other professionals in your field, review jobs, write a blog, post pages, etc.

The BIG benefit and difference between this site and other sites is the following:
1. You can add Google Adsense code to your profile. When you post to your blog, your adsense code will display at the end of your blog. What does this mean. It means that each time you post a blog entry, you gain the chance of making money from Google ads.
2. You can post job opportunities online for FREE.

Monday, July 20, 2009

xslt exists - Why can't I use it?

If you're looking to use the exists function for xslt and you can't figure out why it is a function that doesn't exist, there is a workaround. Instead of using try using This is the alternative workaround.

Friday, June 19, 2009

My date timestamps off by a day

Try and test this, but only during the summer months. Create a new record in your database that requires a timestamp. Is the time off by an hour? If so, you are probably dealing with international times.

What's happening is the local time is different than the international time for the US due to the fact we have daylight savings. Here in the US, the time changes, but to the rest of the world, it doesn't. Note, you may only notice this in the summer. During the winter months, you will not see this error.

Wednesday, April 15, 2009

replace is an unknown xslt function

I'm working client side and found that I couldn't use the replace function in the xslt value arguments. For all of those looking for a workaround, you can use the translate function. To find out more, please visit http://www.w3.org/TR/xpath#function-translate