databinder.eval in code behind

N

Niclas

Hi,

I would like to evaluate a field in a datagrids data source (that is not
bound to a column in the grid) in code behind rather that using inline
code Databinder.Eval(container.dataItem,"MyField"). I don't seem to be
able to use "container" in code behind, Would appreciate if someone
could explain how this statement would look within the ItemdataBound
event.

Thanks

Niclas
 
T

Teemu Keiski

Hi,

If you don't have to use DataBinder.Eval then don't because it involves
reflection. Anyways, what you look for is probably something like

Dim myField As String = DataBinder.Eval(e.Item.DataItem,"MyField")

Container in a databinding expression refers to the DataGridItem. so
therefor replacing Container.DataItem with e.Item.DataItem (e being the e in
event arguments for ItemDataBound)
 
K

Karl Seguin

try e.Item.DataItem

or simply cast e.Item.DataItem to the underlying source, like DataRowView

DataRowView dr = (DataRowView) e.Item.DataItem;
dr["myColumn"];

Karl
 

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,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top