我想继承DATAGRID控件,然后想要实现可以用上下光标键选择DATAGRID中的数据行,这个如何做呢,请大家帮个忙

解决方案 »

  1.   

    我说的这个DATAGRID是WEB页面上的
      

  2.   

    自己写ActiveX吧.把CS的DATAGRID搬过来.
      

  3.   

    给你段js代码,
    <script language="javascript">
    var oldrow;
    var currowno=-1;
    var strReturn; //存储返回值
    var newColor='#ffcc66';
    var oldColor;
    var MaxRowCount;
    function SelectOK(text)
    {
    eval("parent.opener.document.all.TextBox1.value = text");
    parent.close();
    }
    function ChangePage(KeyCode)
    {
        document.all('DataGrid1').focus();
    if ( KeyCode == 33 ) { // 定义 PageUp 键快捷功能
    document.all.PrevPage.click();
    }
    if ( KeyCode == 34 ) { // 定义 PageDown 键快捷功能
    document.all.NextPage.click();
    }
    if ( KeyCode == 36 ) { // 定义 Home 键快捷功能
    document.all.FirstPage.click();
    }
    if ( KeyCode == 35 ) { // 定义 End 键快捷功能
    document.all.LastPage.click();
    }
    if ( KeyCode == 38 ) { // ↑ 键快捷功能
      
    if(currowno==0)//如果已经为第0行,则跳到txtFilter中
    {
    currowno=-1;//设置未为选中状态
    document.all('ROW0').style.backgroundColor=oldColor;
    document.all.txtFilter.focus();
    }
    else
    {
    MoveUp();
    }
      
    }
    if ( KeyCode == 40 ) { // ↓ 键快捷功能
      if(currowno==-1)//如果还没有选中Grid中的行,则设置Grid的第0行为选中状态
      {
         if(document.all('ROW0')!=null)
           document.all('ROW0').click();
         else
           document.all.txtFilter.focus();
      }
      else
      {
    MoveDown();
      }
    }
    if ( KeyCode == 37 ) { // ← 键快捷功能( 上一层 )
    //QueryParent();
    }
    if ( KeyCode == 39 ) { // → 键快捷功能( 下一层 )
    //QueryChild();
    }
    if ( KeyCode == 13 ) { // 回车键

      if(event.srcElement.name=='txtFilter')
      {
        document.all.LastPage.disabled = true;
        document.all.FirstPage.disabled = true;
        document.all.PrevPage.disabled = true;
        document.all.NextPage.disabled = true;
        document.all.GotoPage.disabled = true;   
      }
      else
      {
        if(currowno!=-1)
        {
    document.all.LastPage.disabled = true;
    document.all.FirstPage.disabled = true;
    document.all.PrevPage.disabled = true;
    document.all.NextPage.disabled = true;
    document.all.btnFilteData.disabled = true;
    document.all.GotoPage.disabled = true;
    GotoMain(strReturn);
        }
      }
    }
    }
    function RowFocus(rowno,strValue)
    {
    if(currowno!=-1){
    oldrow.style.backgroundColor=oldColor;
    }
    strReturn = strValue;
    oldColor=document.all('ROW' + rowno).style.backgroundColor;
    oldrow=document.all('ROW' + rowno);

    document.all('ROW' + rowno).style.backgroundColor= newColor;
    currowno=rowno;
    }
       function MoveUp() {
         if(currowno!=-1)
         {
       if(currowno==0)
       currowno=MaxRowCount-1;
       else
       currowno=currowno-1;
      
    document.all('ROW' + currowno).click();
      }
      else
        document.all.txtFilter.focus();

    } function MoveDown() {
    if(currowno==MaxRowCount-1)
       currowno=0;
       else
       currowno=currowno+1;
      
    document.all('ROW' + currowno).click();

    }
    </script>
    <script language="JavaScript" event="onkeydown" for="document">
      if ( event.keyCode == 34 || event.keyCode == 33 || event.keyCode == 35 || event.keyCode == 36 || event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40 || event.keyCode == 13 ) 
      {
    ChangePage(event.keyCode);
      }
      if ( event.keyCode == 27 )
      {       
      history.go(-1);
      } </script>
      

  4.   

    谢谢jimu8130(IBMT43)你的代码,我想把这个集成到DATAGRID控件中,也就是说直接继承DATAGRID,把这段JS代码加进去,以后要实现功能直接用自己做的DATAGRID就可以了,能帮我实现一下吗,谢谢
      

  5.   

    用htc把js封装起来实现
    怎么样?