DataItem Availability?

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top