Click here to Skip to main content
16,004,906 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, help me for the error code Null reference exception was unhandled by user code

Protected Sub lbInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
AccessDataSource1.InsertParameters("Nama").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("txtNama"), TextBox).Text

AccessDataSource1.InsertParameters("NpwpPemotong").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("txtNPWP"), TextBox).Text

AccessDataSource1.InsertParameters("NomorBukti").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("txtNomorBukti"), TextBox).Text

AccessDataSource1.InsertParameters("TglBuktiPemotong").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("txtTglBukti"), Calendar).SelectedDate

AccessDataSource1.InsertParameters("JenisPajak").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("ddlInsertJenisPajak"), DropDownList).SelectedValue

AccessDataSource1.InsertParameters("JumlahPPH").DefaultValue =
DirectCast(GridView1.FooterRow.FindControl("txtJumlahPPH"), TextBox).Text
AccessDataSource1.Insert()
End Sub


thanks

What I have tried:

Null reference exception was unhandled by user code
Posted
Updated 6-Jun-16 12:03pm

1 solution

I think that you have validate if exists controls before you asigned value...


XML
AccessDataSource1.InsertParameters("Nama").DefaultValue = <pre lang="XML">GridView1.FooterRow.FindControl(&quot;txtNama&quot;) <> null ?
DirectCast(GridView1.FooterRow.FindControl(&quot;txtNama&quot;), TextBox).Text</pre> : ""
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900