日期:2011-08-22  浏览次数:20438 次

一下代码可以实现弹出一个DataGrid窗口,该窗口支持up,down以及pageup,pagedown,home,end,Enter键盘操作,在按下Enter键后将选中的值返回初始窗口的TextBox1中。

 

webform1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ComplexTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</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">
   var oldrow
   var currowno;
   var strReturn; //存储返回值
   var newColor='#C0C0C0';
   var oldColor;
   var MaxRowCount;
   function SelectOK(text)
   {
    eval("parent.opener.document.all.TextBox1.value = text");//向弹出该窗体的窗口返回值
    parent.close();
   }
   function ChangePage(KeyCode)
   {
    if ( KeyCode == 33 ) { // 定义 PageUp 键快捷功能
     document.all.PrevPage.click();//调用服务器控件的相应功能
    }
    if ( KeyCode == 34 ) { // 定义 PageDown 键快捷功能
     document.all.下一页:MS SQL压缩数据库日志方法.click();
    }
    if ( KeyCode == 36 ) { // 定义 Home 键快捷功能
     document.all.FirstPage.click();
    }
    if ( KeyCode == 35 ) { // 定义 End 键快捷功能
     document.all.上一页:[转载]改进《遍历文件夹并建成目录树》.click();
    }
    if ( KeyCode == 38 ) { // ↑ 键快捷功能
     MoveUp();
    }
    if ( KeyCode == 40 ) { // ↓ 键快捷功能
     MoveDown();
    }
    if ( KeyCode == 37 ) { // ← 键快捷功能( 上一层 )
     //QueryParent();
    }
    if ( KeyCode == 39 ) { // → 键快捷功能( 下一层 )
     //QueryChild();
    }
    if ( KeyCode == 13 ) { // 回车键
     SelectOK(strReturn);
    }
   }
   function RowFocus(rowno,strValue,bFirst)
   {
    if (bFirst!=0){//如果不是第一次调用该函数
     oldrow.style.backgroundColor=oldColor;//将旧的一行设置回原来的颜色
    }
    strReturn = strValue;//strReturn中保存要返回的值
    oldrow=document.all('ROW' + rowno);//在oldrow中保存旧的行
    oldColor=document.all('ROW' + rowno).style.backgroundColor;//在oldColor中保存当前行的颜色
    document.all('ROW' + rowno).style.backgroundColor= newColor;//设置当前行的颜色为提醒色
    currowno=rowno;//在currowno中保存当前行号
   }
     function MoveUp() {
      if(currowno==0)//如果已经是最上一行则设置光标到最底一行
       currowno=MaxRowCount-1;
      else
       currowno=currowno-1;//否则上移一行
    document.all('ROW' + currowno).click();//调用该行的点击函数
   }

   function MoveDown() {
    if(currowno==MaxRowCount-1)//如果已经是最底一行则设置光标到最底一行上一行
       currown