按下回车键,怎样才能保持当前焦点不变?
我的界面采用一个GridView显示,GridView中所有的单元格我都转换为了模板,大部分模板是TextBox。我遇到了两个问题:
1.我要如何找到某个TextBox模板呢?例如:我的GridView的ID是GridView_Search,其中嵌套着模板TextBox_01,我要如何才能找到这个模板呢?GridView_Search.TextBox_01选不到,要怎么样选择到这个模板呢?
2.界面上有个Button键,用以对GridView_Search的批量更新,当我按回车键就能自动更新,但是由于我的GridView_Search内容比较长,需要滚轮上下滚动。现在的问题是:本来我现在的焦点在某个TextBox模板上,但当我按回车键,当前的焦点会跳到这个Button键上去,而我想把焦点保持在目前的TextBox。
这两个问题该如何解决呢?请各位帮忙看看!谢谢!
--------------------编程问答-------------------- 不是很好弄,毕竟焦点始终定位在一个地方实现起来就费劲。
for肯定是要用的了。 --------------------编程问答-------------------- onkeydown="if(window.event.keyCode==13){return false;}"
--------------------编程问答-------------------- --------------------编程问答--------------------
就这一句加在Button_OnClick{}里面是吗? --------------------编程问答--------------------
<form id="form1" runat="server" onkeypress=" return event.keyCode != 13">--------------------编程问答-------------------- onkeydown="if(window.event.keyCode==13){button1.click(); return false;}"
可以这样直接触发click事件 --------------------编程问答-------------------- 1.我要如何找到某个TextBox模板呢?例如:我的GridView的ID是GridView_Search,其中嵌套着模板TextBox_01,我要如何才能找到这个模板呢?GridView_Search.TextBox_01选不到,要怎么样选择到这个模板呢?
-- 表格->哪一行->哪一列->FindControl
2.界面上有个Button键,用以对GridView_Search的批量更新,当我按回车键就能自动更新,但是由于我的GridView_Search内容比较长,需要滚轮上下滚动。现在的问题是:本来我现在的焦点在某个TextBox模板上,但当我按回车键,当前的焦点会跳到这个Button键上去,而我想把焦点保持在目前的TextBox。
-- 按回车,正常情况下是不会乱跳转的,是不是你们的系统中有什么js帮了你这个倒忙啊? --------------------编程问答-------------------- 将回车转换成Tab换焦点, 是很常用的功能,你先查查看。要不js函数重叠了,你找起原因来很麻烦的。 --------------------编程问答-------------------- 各位大哥!你们发的那一小段代码,让我看不明白,测试了也没通过!我尝试用MaintainScrollPositionOnPostBack 属性,本来是可以的!但因为我给Gridview_Search添加了一个固定的表头,方便使用。因此MaintainScrollPositionOnPostBack属性跳转不到我需要的位置,我在下面添加了图,最右边有两个滚动条,MaintainScrollPositionOnPostBack只能作用于最外面的那个滚动条!
下面附上完整的图和固定表头的代码!
============================图=============================
===========================固定表头的代码======================
<table cellspacing="0" cellpadding="4" rules="cols" border="1"--------------------编程问答-------------------- 谢谢7楼的回复!但能否在具体一些呢?例如我的TextBox1现在是在Gridview_Search的第3行,第5列,该怎么选啊?
id="GridView_Search_Header" style="color: #FFFFFF;
border-color: #DEDFDE; border-width: 1px; border-style: None;
width: 1880px; border-collapse: collapse; font-size: small; font-weight: bold;">
<thead>
<tr style="color: White; background-color: #6B696B; font-weight: bold;">
<th scope="col" style="width: 10px; background-color: #A55129;">序号</th>
<th scope="col" style="width: 46px; background-color: #A55129;">经营项目</th>
<th scope="col" style="width: 98px; background-color: #A55129;">地址</th>
<th scope="col" style="width: 48px; background-color: #A55129;">承租单位</th>
<th scope="col" style="width: 53px; background-color: #A55129;">押金</th>
<th scope="col" style="width: 48px; background-color: #A55129;">年租金</th>
<th scope="col" style="width: 48px; background-color: #A55129;">月租金</th>
<th scope="col" style="width: 42px; background-color: #A55129;">上月欠收</th>
<th scope="col" style="width: 48px; background-color: #A55129;">本月合同应收</th>
<th scope="col" style="width: 42px; background-color: #A55129;">本月总应收</th>
<th scope="col" style="width: 48px; background-color: #A55129;">本月实收</th>
<th scope="col" style="width: 42px; background-color: #A55129;">本月总欠收</th>
<th scope="col" style="width: 47px; background-color: #A55129;">01月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">02月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">03月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">04月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">05月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">06月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">07月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">08月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">09月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">10月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">11月收入</th>
<th scope="col" style="width: 47px; background-color: #A55129;">12月收入</th>
<th scope="col" style="width: 52px; background-color: #A55129;">预收收入</th>
<th scope="col" style="width: 52px; background-color: #A55129;">总收入</th>
<th scope="col" style="width: 52px; background-color: #A55129;">预收总收入</th>
<th scope="col" style="width: 103px; background-color: #A55129;">合同备注</th>
<th scope="col" style="width: 103px; background-color: #A55129;">财务备注</th>
<th scope="col" style="background-color: #A55129;">已收到</th>
</tr>
</thead>
</table>
另外,要找到Gridview中的某个模板,只能先找到它所属的行,再找到它所属的列?只有这种方法!? --------------------编程问答-------------------- jquery试试:
//-----------
当前textbox的ID假如为txtnow
$("#txtnow").blur(function(){$(this).focus()}); --------------------编程问答-------------------- jquery 我还未用过,不懂啊!
补充:.NET技术 , ASP.NET