任何幫助,將不勝感激...代碼工作,直到乾淨錯誤...幫助:錯誤=的NullReferenceException是由用戶代碼未處理
錯誤存在的在行:SqlDataSource3.UpdateParameters(「TechID」)默認值() = CINT(technicianRow( 「TechID」))
這裏充滿VB代碼:
Imports System.Data
Partial Class IncidentAssignment
Inherits System.Web.UI.Page
Public incidentRow As DataRowView
Public technicianRow As DataRowView
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Check to see if a incident has been selected
If GridView1.SelectedIndex = -1 Then
Button1.CommandName = ""
lblmessage.Text = "You must select an incident."
Else
Button1.CommandName = "NextView"
lblmessage.Text = ""
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'Check to see if a incident has been selected
If GridView2.SelectedIndex = -1 Then
Button3.CommandName = ""
lblmessage2.Text = "You must select a technician."
Else
Button3.CommandName = "NextView"
lblmessage2.Text = ""
'Create second DataView
Dim techniciansTable As DataView = CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), DataView)
'Save the selected technician data row
'To the DataRowView object and to session state
technicianRow = techniciansTable(GridView2.SelectedIndex)
Session("Technician") = technicianRow
'Create DataView
Dim incidentsTable As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
'Save PageIndex and PageSize to variables.
Dim pageIndex As Integer = GridView1.PageIndex
Dim pageSize As Integer = GridView1.PageSize
'Calculate the value of the SelectedIndex
Dim selectedIndex As Integer = (pageIndex * pageSize) + GridView1.SelectedIndex
'Save the selected data row to the DataRowView
'object and to session state
incidentRow = incidentsTable(selectedIndex)
Session("Incident") = incidentRow
'Display output from the two DataRowView objects
Label1.Text = incidentRow("Name")
Label2.Text = incidentRow("ProductCode")
Label3.Text = technicianRow("Name")
End If
End Sub
Public Sub btnAssign_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAssign.Click
'Assign data from session state to
'the two DataRowView objects
***ERROR technicianRow = CType(Session("Technician"), DataRowView)
incidentRow = CType(Session("Incident"), DataRowView)
'Update the value of the two parameters to be
'used to store new information about the
'assigned technician
SqlDataSource3.UpdateParameters("TechID").DefaultValue() = CInt(technicianRow("TechID"))
SqlDataSource3.UpdateParameters("IncidentID").DefaultValue() = CInt(incidentRow("IncidentID"))
'Trap errors
Try
'Update the table.
SqlDataSource3.Update()
'Unselect the two GridView controls
GridView1.SelectedIndex = -1
GridView2.SelectedIndex = -1
'Rebind the GridView controls
GridView1.DataBind()
GridView2.DataBind()
'Move to the first view
MultiView1.ActiveViewIndex = 0
Catch ex As Exception
Session("Exception") = ex
Session("Page") = "~/Admin/IndicentAssignment.aspx"
Response.Redirect("~/ErrorMessage.aspx")
End Try
End Sub
Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
End Sub
End Class
正確編輯問題的編碼部分。 – 2011-05-11 05:21:38