DataGrid模板列中TextBox的焦点相应键盘事件

 DataGrid模板列中TextBox的焦点相应键盘事件

     首先在DataGrid中加入模板列:

     < asp:datagrid id="datagrid1" runat="server">

       <AlternatingItemStyle BackColor="#EEEEEE"></AlternatiingItemStyle>

        <ItemStyle Font-Size="12px" ></ItemStyle>

         <HeaderStyle Font-Size="12px" BackColor="#00CCFF"></HeaderStyle>

          <FooterStyle HorizontalAlign="Center"></FooterStyle>

              <Columns>

                   <asp:TemplateColumn>

                           <ItemTemplate>

                                <asp:TextBox id="TextBox1" runat="Server"></asp:TextBox>

                            </ItemTemplate>

                    </asp:TemplateColumn>

                </Columns>

< /asp:datagrid >

   在Page_Load事件中:

       ‘给datagrid绑定数据

                ......

       DataGrid1.DataSource = dst
       DataGrid1.DataBind()

       Dim txt As TextBox
            Dim i As Integer
            For i = 0 To DataGrid1.Items.Count - 1
                txt= DataGrid1.Items(i).FindControl("textbox1")
                txt.Attributes.Add("onkeydown", "if(event.keyCode==13) event.keyCode=9")

           Next

TextBox的焦点即在模板列中加入的TextBox的 TabIndex,每次点击Enter(回车),TextBox的焦点按 Tab 顺序改变

posted @ 2005-02-01 10:41  阿新  阅读(809)  评论(0编辑  收藏  举报