我必须在gridview中的编辑按钮上单击两次

时间:2013-08-20 08:12:29

标签: vb.net asp.net-mvc-4

这是我的代码:

Public Sub GridView1_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
    GridView1.EditIndex = e.NewEditIndex
    If Not IsPostBack Then
        GridView1.DataBind()
    End If
End Sub

Protected Sub GridView1_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
    GridView1.EditIndex = -1
End Sub

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
    Dim strid As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("idtxt"), TextBox).Text
    Dim strFirstName As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("fnmaetxt"), TextBox).Text
    Dim strLastName As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("lnametxt"), TextBox).Text
    Dim strAdress As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("adresstxt"), TextBox).Text
    Dim strEmail As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("emtailtxt"), TextBox).Text
    Dim strPhone As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("phonetxt"), TextBox).Text
    Dim strBirthday As String = DirectCast(GridView1.Rows(e.RowIndex).FindControl("birthdaytxt"), TextBox).Text


    x.updateProfile(strid, strFirstName, strLastName, strAdress, strEmail, strBirthday, strPhone)
    If Not IsPostBack Then
        GridView1.DataBind()
    End If
    GridView1.EditIndex = -1
End Sub

问题是我必须在编辑按钮上单击两次才能进入编辑模式,在取消按钮上单击两次以返回编辑模式,当我更新时我必须重新点击更新才能返回到编辑模式,当我重新点击它时,所有字段都变空..

任何帮助?

1 个答案:

答案 0 :(得分:0)

您需要单击一次以获得焦点,然后再次单击以实际编辑该序列。我为这个问题做的一个解决方法是在网格中处理PreviewLeftMouseButton,我测试点击的元素是否是一个行元素,然后我把它集中在一起,我没有声称要处理点击。