ASP.net - 将焦点设置为编辑行
单击编辑按钮后,如何将焦点设置到 datagridview 行中的特定控件?当网格绑定时,我可以对新行执行此操作,但不能对现有行执行此操作。该控件似乎还不存在。
'这不起作用(现有行)
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
'这对新绑定的行有效
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
How do you set focus to a specific control in a datagridview row after clicking the edit button? 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gvDays_RowDataBound
应该可以工作,问题是您正在使用 = 运算符查看e.Row.RowState
,但RowState
是一个位标志,试试这个
gvDays_RowDataBound
should work, the problem is you are looking ate.Row.RowState
using the = operator, butRowState
is a bitflagtry this