Thursday, April 5, 2007

Allowing Only Numerics in TEXTBOX

In aspx page add following script->
function maskBox(e)
{
var keynum = null;
if(window.event){
keynum = e.keyCode;
}
else if(e.which){
keynum = e.which;
}
if(keynum){
if(keynum==8 || keynum==9){return true;}
else
{return isInt(String.fromCharCode(keynum));
}
}
}
function isInt(test)
{
var ints = "0123456789";
if(ints.indexOf(test)>-1)
{
return true;
}
return false;
}
then in page load just add the following line

textBox1.Attributes.Add("OnKeyDown","return maskBox(event);");

Code to Remove duplicate values from ArrayList

arr ->ArrayList with multiple values ,some unique and some repeating ex. {1,2,3,1,2,4,5}

for(i=0;i < arr.Count-1;i++)
{
for(j=i+1;j < arr.Count;j++)
{
if(arr[i].Equals(arr[j]))
{
arr.RemoveAt(j);
j = j - 1;
}
}
}

On executing code above arr={1,2,3,4,5}