DataGrid模板列中TextBox的焦点相应键盘事件
首先在DataGrid中加入模板列:
< asp:datagrid id="datagrid1" runat="server">
1<alternatingitemstyle backcolor="#EEEEEE">
2<itemstyle font-size="12px"></itemstyle>
3<headerstyle backcolor="#00CCFF" font-size="12px"></headerstyle>
4<footerstyle horizontalalign="Center"></footerstyle>
5<columns>
6<asp:templatecolumn>
7<itemtemplate>
8<asp:textbox id="TextBox1" runat="Server"></asp:textbox>
9</itemtemplate>
10</asp:templatecolumn>
11</columns>
12
13< /asp:datagrid >
14
15在Page_Load事件中:
16
17‘给datagrid绑定数据
18
19......
20
21DataGrid1.DataSource = dst
22DataGrid1.DataBind()
23
24Dim txt As TextBox
25Dim i As Integer
26For i = 0 To DataGrid1.Items.Count - 1
27txt= DataGrid1.Items(i).FindControl("textbox1")
28txt.Attributes.Add("onkeydown", "if(event.keyCode==13) event.keyCode=9")
29
30Next
31
32TextBox的焦点即在模板列中加入的TextBox的 TabIndex,每次点击Enter(回车),TextBox的焦点按 Tab 顺序改变
33
34欢迎批评、讨论!</alternatingitemstyle>