Sunday, January 18, 2009

How to change the color of the selected item of drop downlist


<html>
<head>
<title>
change the color of the selected item
</title>
<script language="javascript">
function chgColor(evt)
{
evt.options[evt.selectedIndex].style.background = 'red';
for(i=0; i< evt.options.length;i++)
{
if(i != evt.selectedIndex)
{
evt.options[i].style.background = '';
}
}
}
</script>
</head>
<body>
<select onchange="chgColor(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="1">5</option>
<option value="2">6</option>
<option value="3">7</option>
<option value="4">8</option>
<option value="1">9</option>
<option value="2">0</option>
</select>
</body>

Monday, January 12, 2009

how to fix decimal places


Decimal.Round
method used to a specified number of decimal places.

decimal
.Round(99.2789m ,2).ToString();

Note

Without the suffix m, the number is treated as a double, thus generating a compiler error.

Output

99.28

Tuesday, January 6, 2009

How to convert strings to lower, upper, titlecase

string str = "xploReDOtneT wElcomeS yOU";

Response.Write("Orginal Text:- " + str + "
Lower :- " + str.ToLower() + "
" + "Upper :- " + str.ToUpper() + "
" + "Title Case :- " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str));



OUTPUT



Orginal Text:- xploReDOtneT wElcomeS yOU

Lower :- xploredotnet welcomes you

Upper :- XPLOREDOTNET WELCOMES YOU

Title Case :- Xploredotnet Welcomes You

Sunday, January 4, 2009

Whats the difference between String.Emtpy and Empty Quotes

String.empty wont create any object while "" will create a new object in the memory for the checking.