databinder.eval in code behind

  • Thread starter Thread starter Niclas
  • Start date Start date
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
 
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)
 
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

Back
Top