P
postings
Hi
Can anybody help? (ASP.NET 1.1)
The event below is triggered when the user clicks an update button
column.
I am trying to update a dataset which eventually gets bound with a
datagrid, with values from that same datagrid.
Note there is no SQL code here, all the dataset data is coming from the
viewstate.
This seems to work fine, OK it's hardly efficient, and yes I should
probably be using a session variable instead.
Back to the dataset problem:
This is the offending line:
rowUpdate.CurrencyID = strCurrency
This is the error message:
[NullReferenceException: Object reference not set to an instance of an
object.]
Note if I take out the line with the error, my datagrid will be
displayed, no problems, it just won't show the updated value. So
everything appears well until I do the update.
I've spend a day looking at this and frankly I'm completely stuck!
Code is below.
Many thanks for you help!
Alex
'------------------------------------------------------------------
Private Sub MyDataGrid_Update(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
MyDataGrid.UpdateCommand
'Gets a value from a drop down list in my datagrid
Dim strCurrency As String = CType(e.Item.Cells(10).Controls(1),
DropDownList).SelectedValue
Response.Write(strCurrency) 'Yep definately got the value
Dim datasetsaved As MyDataset
'Gets dataset data previously saved from viewstate, not efficient but
works
datasetsaved = CType(viewstate.Item("Datagriddata"), MyDataset)
Response.Write("ROW TO EDIT = " & ViewState("ProductInvoiceID")) '
Shows the right row I just edited in a datagrid - definately works
Dim rowUpdate As MyDataset.MyDataTableRow =
MyDataset1.MyDataTable.FindByProductInvoiceID(ViewState("ProductInvoiceID"))
'No errors so far
rowUpdate.CurrencyID = strCurrency 'ERROR MESSAGE TRIGGERED HERE!!!
'Saved updated dataset back to the viewstate for a later time
viewstate.Remove("Datagriddata")
viewstate.Add("Datagriddata", datasetsaved)
'Populate and bind the datagrid
MyDataGrid.DataSource = datasetsaved.MyDataTable
MyDataGrid.databind
'Set datagrid to non editable
MyDataGrid.EditItemIndex = -1
End Sub
'------------------------------------------------------------------
FIN
Can anybody help? (ASP.NET 1.1)
The event below is triggered when the user clicks an update button
column.
I am trying to update a dataset which eventually gets bound with a
datagrid, with values from that same datagrid.
Note there is no SQL code here, all the dataset data is coming from the
viewstate.
This seems to work fine, OK it's hardly efficient, and yes I should
probably be using a session variable instead.
Back to the dataset problem:
This is the offending line:
rowUpdate.CurrencyID = strCurrency
This is the error message:
[NullReferenceException: Object reference not set to an instance of an
object.]
Note if I take out the line with the error, my datagrid will be
displayed, no problems, it just won't show the updated value. So
everything appears well until I do the update.
I've spend a day looking at this and frankly I'm completely stuck!
Code is below.
Many thanks for you help!
Alex
'------------------------------------------------------------------
Private Sub MyDataGrid_Update(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
MyDataGrid.UpdateCommand
'Gets a value from a drop down list in my datagrid
Dim strCurrency As String = CType(e.Item.Cells(10).Controls(1),
DropDownList).SelectedValue
Response.Write(strCurrency) 'Yep definately got the value
Dim datasetsaved As MyDataset
'Gets dataset data previously saved from viewstate, not efficient but
works
datasetsaved = CType(viewstate.Item("Datagriddata"), MyDataset)
Response.Write("ROW TO EDIT = " & ViewState("ProductInvoiceID")) '
Shows the right row I just edited in a datagrid - definately works
Dim rowUpdate As MyDataset.MyDataTableRow =
MyDataset1.MyDataTable.FindByProductInvoiceID(ViewState("ProductInvoiceID"))
'No errors so far
rowUpdate.CurrencyID = strCurrency 'ERROR MESSAGE TRIGGERED HERE!!!
'Saved updated dataset back to the viewstate for a later time
viewstate.Remove("Datagriddata")
viewstate.Add("Datagriddata", datasetsaved)
'Populate and bind the datagrid
MyDataGrid.DataSource = datasetsaved.MyDataTable
MyDataGrid.databind
'Set datagrid to non editable
MyDataGrid.EditItemIndex = -1
End Sub
'------------------------------------------------------------------
FIN