Getting the Value of a field bound to a Repeater

J

John Kotuby

Hello all..
I have what is probably a simple question but I can't find the answer for it
yet.

I have a Repeater bound to a Datatable.

In the OnItemDataBound event controller in the Code Behind I am trying to
pull a value from one of the DataSource fields that is not bound to a
control that is part of the repeater. If it was bound to a label control,
for example I could just do e.Item.FindControl("lblCost").text, to get that
value.

I see an e.Item.DataItem referenced in the Docs and my first impulse was to
try something simple like,
varValue = e.Item.DataItem("fieldname"). value, but that doesn't work.

Can I reference the bound Datasource here somehow?

Or is it as simple as varValue = Eval("fieldname") as it is done in the HTML
page?

Thanks for your answers....
 
D

David

You are along the right lines...

The way I do it is:

object DI = e.Item.DataItem;

string MyVal = DataBinder.Eval(DI, "FieldName").ToString();

I don't know how efficient this is, but it works for me. Thinking more about
it, you might be able to do...

string MyVal = DataBinder.Eval(e.Item.DataItem, "FieldName").ToString();

though I have never tried it.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
B

bruce barker

if your repeater is bound to a datatable then the dataitem will be a
DataRow. you just need to cast it to use it.

string value = ((DataRow)e.Item.DataItem)["fieldname"].ToString();


-- bruce (sqlwork.com)
 
J

John Kotuby

Thank you for your answers gentlemen,

Both syntax formats seem to work.
I appreciate the help.
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top