将焦点设置为asp.net中gridview的下一个单元格 [英] Set focus to next cell of a gridview in asp.net

查看:81
本文介绍了将焦点设置为asp.net中gridview的下一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有gridview有组合框和文本框。组合框和文本框在回发期间都有一些功能。我希望在回发后将焦点更改为下一个单元格。

I have gridview having combo boxes and text boxes.Both the combobox and textbox have some function during post back.I want change the focus to the next cell after post back .

推荐答案

如果您使用TemplateField



If you use TemplateField like

<asp:TemplateField>
            <ItemTemplate>
                <%#Eval("EmailName") %>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtEdit" runat="server" Text='<%#Eval("EmailName") %>' />
            </EditItemTemplate>
        </asp:TemplateField>





您可以在RowEditing中执行此操作,例如





You could do it in RowEditing, for example

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //Normal turning to edit
            GridView1.EditIndex = e.NewEditIndex;
            BindGrid();

            //Set the focus to control on the edited row
            GridView1.Rows[e.NewEditIndex].FindControl("txtEdit").Focus();
        }





手动绑定网格,因此设置索引并调用数据绑定功能。但是,对于BoundField,它可能是这样的:





binding the grid manually, therefore there is setting the index and calling databinding functions. However, with BoundField it could be something like:

GridView1.Rows[e.NewEditIndex].Cells[1].Controls[0].Focus();





其中Cells [index]是你应该修改的那个列有问题(仍然在RowEditing中执行)



如果您使用数据源控件,在RowDataBound中执行它可能是可行的:








where Cells[index] is the one you should be modifying based on which column it is in question (still doing it in RowEditing)

In case you use data-source controls, it might be feasible to do it in RowDataBound:



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowState == DataControlRowState.Edit)
            {
                //Set the focus to control on the edited row
                e.Row.Cells[1].Controls[0].Focus();

                //Or to a specific control in TemplateField
               // e.Row.FindControl("txtEdit").Focus();
            }
        }


GridView1.Rows [e.NewEditIndex] .FindControl(txtEdit)。焦点();



尝试这个
GridView1.Rows[e.NewEditIndex].FindControl("txtEdit").Focus();

try this


这篇关于将焦点设置为asp.net中gridview的下一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆