Goodday!
I wanted to create a temporary gridview before saving.When I enter values on textboxs , click Add, then it will populate the gridview.
The problem:
1. When I have successfully added values for the first row, and add new values. It overwrites the first row values. I wanted to make the new values on the next row. Or just create a new row then show the new values that has been inputted from the textboxes.
Here is my code:
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(6) {New DataColumn("Code"), New DataColumn("Description"), New DataColumn("Specification"), New DataColumn("Availability"), New DataColumn("Storage Location"), New DataColumn("Quantity"), New DataColumn("Critical")})
dt.Rows.Add(componentCodeTextbox.Text, DescriptionTextbox.Text, txt_specs.Text, cb_availability.SelectedItem, txt_location.Text, QuantityTextbox.Text, CriticalTextbox.Text)
ViewState("dt") = dt
TempGV.DataSource = TryCast(ViewState("dt"), DataTable)
TempGV.DataBind()
End Sub
But has error in :
Dim dr As datarow = dt.NewRow()
ERROR: object null reference exception
do I have to add other code so that I could add new row?
Any help would be much appreciated. Thanks in advance.