I tried to write a code to assign a value when I change the DetailsView to insert mode. for example, I need to assign an ID in a field:
1- I converted the field to (edit template).
2- I give it a new id.
3- I used this code in a Button_Click as below :
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DetailsView1.ChangeMode(DetailsViewMode.Insert)
Dim txt As TextBox
If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
txtBox = DirectCast(DetailsView1.FindControl("TextBox1"), TextBox)
txtBox .Text = ViewState("932")
End If
End Sub
but when I clicked the button it gives me this error.
Object reference not set to an instance of an object.
any help please ?