GridView文本框导航,使用asp.net 2008使用Arrow(上/下)键 [英] GridView textbox Navigation using Arrow(up/down) keys using asp.net 2008
本文介绍了GridView文本框导航,使用asp.net 2008使用Arrow(上/下)键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前在我的程序的ItemTemplate字段下使用网格控件和文本框控件.因此,如何使用asp.net 2008使用箭头(上/下)键设置文本框导航
I have used to grid control and textbox control under ItemTemplate field to my program. So, How to set the text box Navigation using Arrow(up/down) keys using asp.net 2008
推荐答案
以下是示例代码-
Here is the Sample Code -
<script language="javascript" type="text/javascript">
function keyPressed(TB, e) {
var rowscount = document.getElementById('<%=GridView1.ClientID%>').rows.length;
if (e.keyCode == 40 || e.keyCode == 13) {
if (TB.split("TextBox1_")[1] < (rowscount-2))
document.getElementById(TB.split("TextBox1_")[0] + 'TextBox1_' + eval(TB.split("TextBox1_")[1] + '+1')).focus();
}
if (e.keyCode == 38) {
if (TB.split("TextBox1_")[1] >= 1)
document.getElementById(TB.split("TextBox1_")[0] + 'TextBox1_' + eval(TB.split("TextBox1_")[1] + '-1')).focus();
}
}
</script>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="AccessTypeID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="type" SortExpression="type">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("type") %>' onkeyup="keyPressed(this.id,event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%
ConnectionStrings:omfConnectionString %> ; " span> SelectCommand =" 选择*从[tblAccessType]在哪里([类型]类似于'%'+ @type +'%')" < SelectParameters > < asp:Parameter 默认值 =" 名称 =" 类型 =" 字符串" / > < /SelectParameters > < /asp:SqlDataSource >
ConnectionStrings:omfConnectionString %>" SelectCommand="SELECT * FROM [tblAccessType] WHERE ([type] LIKE '%' + @type + '%')"> <SelectParameters> <asp:Parameter DefaultValue="work phone" Name="type" Type="String" /> </SelectParameters> </asp:SqlDataSource>
这篇关于GridView文本框导航,使用asp.net 2008使用Arrow(上/下)键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文