Getting the Value of a field bound to a Repeater

Discussion in 'ASP .Net' started by John Kotuby, Apr 19, 2007.

  1. John Kotuby

    John Kotuby Guest

    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....
    John Kotuby, Apr 19, 2007
    #1
    1. Advertising

  2. John Kotuby

    David Guest

    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" <> wrote in message
    news:...
    > 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....
    >
    >
    David, Apr 19, 2007
    #2
    1. Advertising

  3. John Kotuby

    bruce barker Guest

    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....
    >
    >
    bruce barker, Apr 19, 2007
    #3
  4. John Kotuby

    John Kotuby Guest

    Thank you for your answers gentlemen,

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

    "John Kotuby" <> wrote in message
    news:...
    > 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....
    >
    >
    John Kotuby, Apr 19, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rhiner Dan
    Replies:
    1
    Views:
    742
    Mike Wahler
    Mar 27, 2005
  2. Phillip Vong
    Replies:
    0
    Views:
    413
    Phillip Vong
    Jul 27, 2006
  3. Nathan Sokalski

    Getting the data bound to a Repeater

    Nathan Sokalski, Dec 6, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    299
    Milosz Skalecki [MCAD]
    Dec 6, 2007
  4. Nathan Sokalski

    Getting the data bound to a Repeater

    Nathan Sokalski, Dec 6, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    148
    Milosz Skalecki [MCAD]
    Dec 6, 2007
  5. jr
    Replies:
    3
    Views:
    414
Loading...

Share This Page