开发者

I can't get GridView's RowDataBound update rows after the first row?

开发者 https://www.devze.com 2023-04-13 07:35 出处:网络
Helo Experts again. I have asked a question similar to this in the past. I was able to resolve it by removing gvRowDataBound completely from the code. This is similar code except I can\'t remove gvRo

Helo Experts again.

I have asked a question similar to this in the past. I was able to resolve it by removing gvRowDataBound completely from the code. This is similar code except I can't remove gvRowDataBound sub.

The issue is that when you click the Edit button of the first row, it allows you to successfully update that row.

After the first row, if you click on thr edit button of any other row, enter the value to update, it doesn't update that row.

Instead, the cursor moves down to the next row.

I didn't design this and having difficulty figuring out what needs to change.

I would really, really appreciate your help.

Thanks SO much in advance.

Here is the sub that is giving me fits. I can provide additional info if needed

Protected Sub gvRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim drv As DataRowView = e.Row.DataItem
        Dim nameid As String = drv("empl_first").ToString & Space(5) & drv("empl_last").ToString & Space(5) &开发者_开发百科 Space(5) & drv("employee_ID").ToString
        If tmpEmplID <> drv("employee_ID").ToString Then
            tmpEmplID = drv("employee_ID").ToString
            Dim tbl As Table = e.Row.Parent
            If Not IsDBNull(tbl) Then
                Dim row As New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal)
                Dim cell As New TableCell
                cell.ColumnSpan = Me.GridView1.Columns.Count

                cell.Width = Unit.Percentage(100)
                cell.Style.Add("font-weight", "bold")
                cell.Style.Add("background-color", "#c0c0c0")
                cell.Style.Add("color", "white")

                Dim span As New HtmlGenericControl("span")
                'span.InnerHtml = "Employee ID:    " & nameid & Space(10)

                If drv("date_stamp_appr").ToString = "" Then
                    span.InnerHtml += " <input type='button' ID='" & tmpEmplID & "' value='Approve' onclick='GetHere(""" & tmpEmplID & """)'></input>"
                Else
                    span.InnerHtml += " <b>APPROVED ON: " & drv("date_stamp_appr").ToString & "</b>"
                End If
                Dim linkBtn As LinkButton = CType(e.Row.Cells.Item(0).Controls.Item(2), LinkButton)
                linkBtn.OnClientClick = "return confirm('Are you sure you want to   delete this entry?');"

                cell.Controls.Add(span)
                row.Cells.Add(cell)

                tbl.Rows.AddAt(tbl.Rows.Count - 1, row)

            End If

        End If
    End If

End Sub


Try using the RowEditing event for the GridView instead of the RowDatabound event.

0

精彩评论

暂无评论...
验证码 换一张
取 消