问题描述
大家好,有一gridview问题需要请救.在一个gridview控件中,有30行,10列,都是textbox列,用户输入数据时,从第一行,第一列开始输入,每输一次数据按一次回车,当按下回车后,光标自动停在第二列,三列,四列......,到第十列时用户按回车键,光标要到第二行,第一列,以此类推......
解决方案
解决方案二:
用脚本来完成可以通过给TextBox的Id赋值来完成
解决方案三:
//DEMO<%@PageLanguage="C#"%><%@ImportNamespace="System.Data"%><%@ImportNamespace="System.Text"%><%--http://topic.csdn.net/u/20080706/11/e66b378d-9307-4663-9c2c-e0855f42965e.html--%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><scriptrunat="server">voidShowStudentData(){DataTabledt=CreateSampleData();GridView1.DataSource=dt;GridView1.DataBind();}#regionsampledatastaticDataTableCreateSampleEmptyDataTable(){DataTabletbl=newDataTable("Student");tbl.Columns.Add("StudentNO",typeof(string));tbl.Columns.Add("FirstName",typeof(string));tbl.Columns.Add("LastName",typeof(string));tbl.Columns.Add("Age",typeof(int));tbl.Columns.Add("Gender",typeof(string));returntbl;}staticDataTableCreateSampleData(){DataTabletbl=CreateSampleEmptyDataTable();tbl.Rows.Add("20021342","Jack","Wu",25,"M");tbl.Rows.Add("20025341","Jue","You",23,"F");tbl.Rows.Add("20022254","Viky","Huang",24,"F");tbl.Rows.Add("20022231","Leo","Wong",24,"M");returntbl;}#endregionprotectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){ShowStudentData();}}</script><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>GridView</title><scripttype="text/javascript">functionkeyEnter(sender,arg){if(window.event.keyCode==13){//debugger;varrow=sender.parentNode.parentNode;if(arg.length>1&&arg[1]){row=row.nextSibling;}if(row==null)return;varipts=row.getElementsByTagName("input");vartxt2;for(vari=0;i<ipts.length;i++){if(ipts[i].type=="text"&&ipts[i].id.indexOf(arg[0])>0){txt2=ipts[i];}}if(txt2!=null)txt2.focus();}}</script></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="false"><columns><asp:TemplateField><ItemTemplate><asp:TextBoxid="TextBox_1"onkeypress="keyEnter(this,['TextBox_2'])"runat="server"Text='<%#Eval("FirstName")%>'/></ItemTemplate></asp:TemplateField><asp:TemplateField><ItemTemplate><asp:TextBoxid="TextBox_2"onkeypress="keyEnter(this,['TextBox_3'])"runat="server"Text='<%#Eval("LastName")%>'/></ItemTemplate></asp:TemplateField><asp:TemplateField><ItemTemplate><asp:TextBoxid="TextBox_3"onkeypress="keyEnter(this,['TextBox_1',true])"runat="server"Text='<%#Eval("Age")%>'/></ItemTemplate></asp:TemplateField></columns></asp:GridView></div></form></body></html>
解决方案四:
感谢晓风残月,我还有一个问题没有说清楚,在gridview中的txtTitle_TextChanged有一事件,每次填写完一个textbox后,都会触发该事件,然后光标会回到页面第一个textbox,如果用上面的方法,就不能实现了.