Saturday, January 31, 2009

Single line If Statement.

string name = Session["UserName"];

if(string.isNullOrEmpty(name))
Response.Write("welcome guest");
else
Response.Write("welcome "+name);

You can write it in single line as below.

Response.Write((string.isNullOrEmpty(name)) ? "Welcome guest" : "Welcome "+name);

The HTML Label Tag Benifits

Make your forms accessible to screen readers
Make your forms easy to click on
Give your CSS more to hold on to


To see more detail, check this Link

Use generics with drop down list

You can use generice to bind with drop down list. Suppose you have a class Country.

public class Country
{
int id;
string countryName;

public int ID
{
get { return id; }
}


public string CountryName
{
get { return countryName; }
set { countryName = value; }
}
}

List objCountry = new List();
objCountry = objCountry.FetchCountries();
ddlCountryList.DataSource = objCountry;
ddlCountryList.DataTextField = "CountryName";
ddlCountryList.DataValueField = "ID";
ddlCountryList.DataBind();

The ddlCountryList is an asp.net drop down list control.

Wednesday, January 21, 2009

Designing a GUI

A tip for designing a GUI(Graphical user interface) is that the items in the menu is in the range of 5 to 9. The reason is the famous rule of George A. Miller Seven plus or minus two. it states that the human minds at a time remember seven plus or minus two items. so it is a good practice to not make more than seven items in a menu.