Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting the Value of a field bound to a Repeater

Reply
Thread Tools

Getting the Value of a field bound to a Repeater

 
 
John Kotuby
Guest
Posts: n/a
 
      04-19-2007
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....


 
Reply With Quote
 
 
 
 
David
Guest
Posts: n/a
 
      04-19-2007
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


"John Kotuby" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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....
>
>



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      04-19-2007
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)



John Kotuby wrote:
> 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....
>
>

 
Reply With Quote
 
John Kotuby
Guest
Posts: n/a
 
      04-19-2007
Thank you for your answers gentlemen,

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

"John Kotuby" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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....
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
Getting the data bound to a Repeater Nathan Sokalski ASP .Net 2 12-06-2007 08:45 PM
Getting the data bound to a Repeater Nathan Sokalski ASP .Net Web Controls 2 12-06-2007 08:45 PM
Passing Bound Object value to another Bound Object Phillip Vong ASP .Net 0 07-27-2006 10:54 PM
Getting lower-bound and upper-bound of strings input Rhiner Dan C++ 1 03-27-2005 02:03 AM



Advertisments