I have created an 'Always' editable datagrid. All the rows are editable
and they all have textboxes, checkboxes, or dropdown lists. Some of the
columns are read only, but that is not an issue for the up and down
arrows since these columns will never have focus anyway. I think I have
figured out how to accomplish what I need but I am really weak with
javascript. I am trying to pass in the ID of the textbox, use regular
expression to parse out the numeric component of that id and either
increment it or decrement it, then set the focus on the desired control.
I have been able to capture the arrow keys with the OnKeyUp event. I
can't seem to get the code to work. I'm having a problem with casting
from numeric to string. The following is a simple test webpage with a
test script that attempts to display an alert incrementing the value of
the TextBox ID which is ID="TB1234a". If this code worked, an alert
would display "1235". Obviously, this test program doesn't perform all
the functionality I'm trying to write, but it is an important step in
the process. Do you know why this code doesn't work? The following
page has no code in the Code Behind:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Test.aspx.vb"
Inherits="ProductMngt.Test" debug="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<META name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<META name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<META name="vs_defaultClientScript" content="JavaScript">
<META name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<SCRIPT language="javascript">
function newalert(TB)
{
window.alert(TB.id);
}
function keyalert(TB)
{
var rel;
var newval = 0;
var TBName = new String();
rel = /[0-9]+/;
TBName = TB.name;
var oldval = new String(TBName.match(rel));
//var newval : Object = (int(oldval) + 1);
if (oldval==""){
window.alert("NULL");
}
else
{
//newval = (int(oldval) + 1);
newval = int(oldval) + 1;
window.alert(newval);
}
/*
var VK_LEFT = 37;
var VK_UP = 38;
var VK_RIGHT = 39;
var VK_DOWN = 40;
switch (event.keyCode){
case VK_LEFT : {window.alert("Left");break}
case VK_UP : {window.alert("Up");break}
case VK_RIGHT : {window.alert("Right");break}
case VK_DOWN : {window.alert("Down");break}
default : {window.alert(event.keyCode)};
//window.alert(event.keyCode);
}
*/
}
</SCRIPT>
</HEAD>
<BODY ms_positioning="GridLayout">
<FORM id="Form1" method="post" runat="server">
<%-- Comments --%>
<INPUT onclick=newalert(Form1.TB) id="TB" name="TB1234a"
style="Z-INDEX: 103; LEFT: 340px; POSITION: absolute; TOP: 212px"
type="text" onkeyup=keyalert(Form1.TB)>
</FORM>
</BODY>
</HTML>
You can see that I have commented out some code that tests the capture
of the arrow keys. That code worked fine.