DataItem Availability?

  • Thread starter Thread starter Adam Knight
  • Start date Start date
A

Adam Knight

Hi all,

A quick question on data item availability?
See the function below. Upon clicking an button the following function is
executed.

My problem is, whenever the DataItem property is access nothing is return,
except a null exception.

Can i only use the DataItem while databind?

If so, what suggestions do you have to retrieve a db value relating to a
particular datagrid item?

Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'variable declarations
Dim blnCorrect As Boolean
Dim dgAnswerOptions As DataGrid

'iterate through data list items
For Each dlstItem As DataListItem In dlstAssessment.Items

'locate answer options datagrid control; store it in a local
variable
dgAnswerOptions =
CType(dlstItem.FindControl("dgAnswerOptions"),DataGrid)

'boolean variable indicating question has been answered correctly
blnCorrect = True

'iterate through data grid items
For Each dgItem As DataGridItem In dgAnswerOptions.Items

Try

Response.Write("Data Item: " &
dgItem.DataItem("is_correct"))

Catch

End Try

Next

Next

End Sub

Help appreciated!!
Adam
 
Hi Adam,

Web application is different from windows application. The web control's
datasource, such as DataItem for datagrid, datalist, and repeatpter, is not
tightly bound with the control. The dataitem is only available when binding
data. Once rendering to client-side, it's gone. Hence after postback, it's
not available any more. If you want to use it, you should save it in
SessionState when being created, then retrieve it from SessionState.

HTH

Elton Wang
 
Back
Top