Getting the value of another cell in Grid in ItemTemplate

Discussion in 'ASP .Net Datagrid Control' started by msnews.microsoft.com, Aug 9, 2004.

  1. Here's a tough one, but one I've run into serveral times now.

    I know that you can use DataBinder.Eval(Container, "Field") to set a value
    of a control in an item template. Works great.

    However I need to do some inline code, because some of the items I need to
    display one set of controls, and some of the items I need to display another
    set of controls based on the value in the record.

    So I tried to do this:

    <%if (DataBindiner.Eval(Container, "Field").ToString() == string.Empty) {%>
    HTML controls
    <%} else {%>
    Some other HTML Controls
    <%}%>

    What I get is an error that container doesn't exist.

    Does anyone know how I can get the value of a field and then have the above
    if work correctly?

    I tried setting it to a label's text property (that works fine) and then
    testing the label's text property in the if, but of course that doesn't
    work, because it doesn't know that control because it's part of the
    ItemTemplate.

    Thanks!
    James Hancock
    msnews.microsoft.com, Aug 9, 2004
    #1
    1. Advertising

  2. Hi James,

    Just checking that it isn't just a typo? See the spelling of DataBindiner

    Ken


    "msnews.microsoft.com" <~> wrote in message
    news:%...
    > Here's a tough one, but one I've run into serveral times now.
    >
    > I know that you can use DataBinder.Eval(Container, "Field") to set a value
    > of a control in an item template. Works great.
    >
    > However I need to do some inline code, because some of the items I need to
    > display one set of controls, and some of the items I need to display
    > another set of controls based on the value in the record.
    >
    > So I tried to do this:
    >
    > <%if (DataBindiner.Eval(Container, "Field").ToString() == string.Empty)
    > {%>
    > HTML controls
    > <%} else {%>
    > Some other HTML Controls
    > <%}%>
    >
    > What I get is an error that container doesn't exist.
    >
    > Does anyone know how I can get the value of a field and then have the
    > above if work correctly?
    >
    > I tried setting it to a label's text property (that works fine) and then
    > testing the label's text property in the if, but of course that doesn't
    > work, because it doesn't know that control because it's part of the
    > ItemTemplate.
    >
    > Thanks!
    > James Hancock
    >
    Ken Cox [Microsoft MVP], Aug 11, 2004
    #2
    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. Vannela
    Replies:
    1
    Views:
    546
    Oleg Medyanik
    Dec 12, 2003
  2. msnews.microsoft.com
    Replies:
    1
    Views:
    1,434
    Ken Cox [Microsoft MVP]
    Aug 11, 2004
  3. Bennett Haselton
    Replies:
    1
    Views:
    5,320
    Joe Fallon
    Sep 24, 2004
  4. Replies:
    1
    Views:
    340
  5. msnews.microsoft.com

    Getting the value of another cell in Grid in ItemTemplate

    msnews.microsoft.com, Aug 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    126
    Ken Cox [Microsoft MVP]
    Aug 11, 2004
Loading...

Share This Page