nullreferenceexception was unhandled by user code in

Posted by Earlcools under ASP.NET on 8/1/2012 | Points: 10 | Views : 2655 | Status : [Member] | Replies : 0
I am trying to update multiples rows at once

Partial Class TeacherPages_ViewStudents
Inherits System.Web.UI.Page

Private tableCopied As Boolean = False
Private originaldatatable As System.Data.DataTable
Protected Sub gridview1_rowdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Not tableCopied Then
originaldatatable = CType(e.Row.DataItem, System.Data.DataRowView).Row.Table.Copy()
ViewState("originalvaluesDataTable") = originaldatatable
tableCopied = True
End If
End If
End Sub

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles UpdateButton.Click
originaldatatable = CType(ViewState("originalValuesDataTable"), System.Data.DataTable)

For Each r As GridViewRow In GridView1.Rows
If isrowmodified(r) Then GridView1.UpdateRow(r.RowIndex, False)

' Rebind the Grid to repopulate the original values table.
tableCopied = False
End Sub
Protected Function isrowmodified(ByVal r As GridViewRow) As Boolean
Dim currentStudentId As Integer
Dim currentComment As String
Dim currentAsbent As Integer
Dim currentLate As Integer

currentStudentId = Convert.ToInt32(GridView1.DataKeys(0).Value)
currentComment = CType(r.FindControl("txtComment"), TextBox).Text

Dim row As System.Data.DataRow = _
originaldatatable.Select(String.Format("StudentId = {0}", currentStudentId))(0)

If Not currentComment.Equals(Row("comment").tostring()) Then Return False
Return False
End Function


(No response found.)

Login to post response