[英]ASP.net - Set focus to editing row
How do you set focus to a specific control in a datagridview row after clicking the edit button? 单击编辑按钮后,如何将焦点设置到datagridview行中的特定控件? I'm able to do it for a new row when the grid is binding, but not for an existing row. 当网格绑定时,我能够为新行执行此操作,但不能对现有行执行此操作。 The control doesn't seem to exist yet. 该控件似乎尚未存在。
'This doesn't work (existing row) '这不起作用(现有行)
Protected Sub gvDays_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles gvDays.RowEditing
Try
gvDays.EditIndex = e.NewEditIndex
gvDays.Rows(e.NewEditIndex).FindControl("txtDayText").Focus()
Catch ex As Exception
Helper.WriteException(ex)
End Try
End Sub
'This does work for a newly bound row '这适用于新绑定的行
Private Sub gvDays_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDays.RowDataBound
If e.Row.RowState = DataControlRowState.Edit Then
e.Row.Cells(3).Controls(0).Focus()
End If
End Sub
gvDays_RowDataBound
should work, the problem is you are looking at e.Row.RowState
using the = operator, but RowState
is a bitflag gvDays_RowDataBound
应该工作,问题是你正在使用=运算符查看e.Row.RowState
,但RowState
是一个位标志
try this 尝试这个
Private Sub gvDays_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDays.RowDataBound
If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit Then
e.Row.Cells(3).Controls(0).Focus()
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.