做项目的时候碰到一个很头疼的问题,就是,用gridview生成很多的行的时候,gridview里有很多的文本框,其中有个文本框记录的是数量,ID是TextBox5,不变的,现在有一个问题就是,当gridview中有很多的行的时候,当光标在这个文本框里的时候,按 “下” 方向键的时候,要把光标定位到下一行的那个文本框中去....请高手教一教啊!

解决方案 »

  1.   

    一般都是设置tabindex
    通过tab键来切换焦点
      

  2.   

    把键盘的向下的按钮的ASC码换成TAB的ASC具体是多少你自己百度一下
      

  3.   

    这个方法试过啊,不过gridview一行里有很多个文本框,焦点切换只会换到下一个文本框,不会跳到下一行...
      

  4.   

    在textbox中通过onkeyup等判断回车键等
    查询下行textbox
      

  5.   

    "下"方向键是 40 TAB是9都试过了!只是换到下一个文本框,不会跳到下一行...
      

  6.   

    初始化你的那些textbox时,为他们附一个属性,比如: protected void Page_Load(object sender, EventArgs e)
            {
                for(int i=0; i < 10; i++)
                {
                    //这样每个textbox都有一个规律的索引值
                    this.tb.Attributes.Add("Index",i.ToString());
                }
            }
    //前台,为他们注册事件
    <input Index="1" onkeyup="move(this)"/>
    <input Index="2" onkeyup="move(this)"//>
    <input Index="3" onkeyup="move(this)"//>
    var move = function(obj){
        var direction;
        if(window.event.keyCode == 38)
            direction = "up";
        else  if(window.event.keyCode == 38)
            direction = "down";
        else return;    if(!obj.getAttribute("Index"))
            return ;
        var nextIndex = direction == "up" ? (~~obj.getAttribute("Index"))--
            : (~~obj.getAttribute("Index"))++;    var inputList = document.getElementsByTagName("input");
        for(var i=0 ; i<inputList.length;i++){
            if(inputList[i].getAttribute("Index") == nextIndex){
                inputList[i].focus();
            }
        }
    }
    //这是思路,具体的逻辑还要自己写
      

  7.   

    网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    时间戳: Thu, 19 Aug 2010 06:19:53 UTC
    消息: 不能给 '[number: 2]' 赋值
    行: 16
    字符: 5
    代码: 0
    URI: file:///C:/Users/Administrator/Desktop/gh%20fs.html有错误....
      

  8.   

    大哥所给的东西里面已经有我想要的东西了,只是,
     var inputList = document.getElementsByTagName("input");
        for(var i=0 ; i<inputList.length;i++){
            if(inputList[i].getAttribute("Index") == nextIndex){
                inputList[i].focus();
            }
        }你可以讲一讲这一段代码的意思给我听听吗?
    我现在还没有去测试
    不过我的解理,
    var inputList = document.getElementsByTagName("input"); // 找到页面所有input元素
    for(var i=0 ; i<inputList.length;i++){ //遍历元素的 Index属性
            if(inputList[i].getAttribute("Index") == nextIndex){ //如果属性名相吻合
                inputList[i].focus(); //把焦点给这个控件
            }
        }
    对吗?
      

  9.   

    [symbol_bc]
    谢谢啦,现在可以啦!但是有一个问题!
    var nextIndex = direction == "up" ? (~~obj.getAttribute("Index"))--
            : (~~obj.getAttribute("Index"))++;
    这一句应该改成
    var nextIndex = direction == "up" ? (~~obj.getAttribute("Index"))-1
            : (~~obj.getAttribute("Index"))+1;
    这样系统才不会报错!用++ -- 系统会提示无法给 number:1 赋值