Feb 23, 2009

Handling the slected item in a Multisimple ListBox

List indexList = new List();
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
int index = ((ListBox)sender).IndexFromPoint(pt);
listBox1.ClearSelected();

if (indexList.Contains(index))
indexList.Remove(index);
else
indexList.Add(index);

if (0 == index)
{
listBox1.SelectedIndex = index;
indexList.Clear();
}
else
{
foreach (int tempIndx in episodeTypeIndxList)
{
listBox1.SelectedIndices.Add(tempIndx);
}
}
}

Feb 5, 2009

Restrict the Number of Chars in Text Area

Javascript Function:
function ValidateTA(obj)
{
var str = new String(obj.value);
if(str.length >= 10)// Here the Max char is 10
{
window.event.returnValue = 0;
}
}

HTML Control:
textarea id="TextArea1" onkeydown="ValidateTA(this)" cols="20" rows="2"



Note: We can implement the same logic for the requiremens like, "only char should be entered or Only numbers should be entered in a text box"