日期:2014-05-20  浏览次数:20567 次

aspnet中Gridview如何实现敲回车进入下一行?或者用方向键在不同的行之间切换?
asp.net中,输入完一行的数据后想切换到下一行,只能使用TAB键,如何使用方向键进行行与行之间的切换?或者敲回车直接进入下一行?

------解决方案--------------------
<input onkeydown= "if(event.keyCode==13)event.keyCode=9 ">
------解决方案--------------------
sendkey
------解决方案--------------------
你的文本框是怎样放在GridView里的?
------解决方案--------------------
下面这个是在 datagrid里的,gridview里应该差不多吧。。。

<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
/*
///本函数是在keypressed2上扩展得来.对keypressed2进行优化及按目前需求增加相应功能
///ZLJ 2007-11-05-22:00
/// 在datagrid里,跟据所按下的方向键,对当前光标位置做相对应的跳转
///缺陷:目前只能对Datagrid中的textbox模板列进行控制.
 
若为最后一列时,则光标转向下一行的第一列,若为最后一行的最后一列则按向右光标键不做反应。
若为第一列时,按向左则光标转向上一行的最后一列。
若为最后一行时,按向下光标则新增一行
若为第一行时,按向上光标则不做反应。
若下一个目的地只是单纯的表格,没有子控件(textbox),则继续寻找下一个单元格,直到找到适合的单元格为止
*/
function keyPressed(TB)
{
var tblGrid = document.getElementById("DataGrid1");
var TBID = document.getElementById(TB);//当前ID
var CurCellID=TBID.parentElement;//当前TD
var CurCellIndex=CurCellID.cellIndex;//当前是第几列
var CurRowIndex= CurCellID.parentElement.rowIndex;//当前是第行;
var rowcount = tblGrid.rows.length; //总行
var CellCount =tblGrid.rows[CurRowIndex].cells.length;//当前行的总列数
var TargateRow=-1 ;//目标行(默认值为-1)
var TargateCell=-1 ;//目标列 (默认值为-1)
var R,C;


if (event.keyCode == 37 || event.keyCode == 38 || 
event.keyCode == 39 || event.keyCode == 40|| event.keyCode == 13)
{
if (tblGrid.rows[CurRowIndex].cells[CurCellIndex].children[0] != null)
{
if (tblGrid.rows[CurRowIndex].cells[CurCellIndex].children[0].id == TBID.id)
{

//向下光标****************************************************************************
if (event.keyCode == 40 )//Buttom
{
if (CurRowIndex<rowcount-1)
{
if (tblGrid.rows[CurRowIndex + 1].cells[ CurCellIndex].children[0] != null)
{
if (tblGrid.rows[CurRowIndex + 1].cells[ CurCellIndex].children[0].type == 'text')
{
//downvalue
tblGrid.rows[CurRowIndex + 1].cells[CurCellIndex].children[0].focus(); 
return false;
}

}
else
{
//当在最后一行按向下光标键时,新增一行空白行


}
}
//END****************************************************************************

//向上光标(当前行必须大于第一行)******************************************************
if (event.keyCode == 38 && CurRowIndex > 1 )//up
{
if (tblGrid.rows[CurRowIndex - 1].cells[
CurCellIndex].children[0] != null){
if (tblGrid.rows[CurRowIndex - 1].cells[
CurCellIndex].children[0].type == 'text'){
//upvalue
tblGrid.rows[CurRowIndex - 1].cells[