Passing value into DataBinder.Eval(Container.DataItem, "Property")

Discussion in 'ASP .Net' started by Tom Lee, Dec 8, 2003.

  1. Tom Lee

    Tom Lee Guest

    Hi all,
    I have the following problem and I cannot solve it. If
    anyone can help me solve this problem.
    I use the following code
    <%#DataBinder.Eval(Container.DataItem, "Property")%>
    to display Property from database. How do I dynamically
    change the value "Property" to another one say "Name" to
    display the Name from database or to any other variable
    that I want.
    Thanks.
    Tom Lee, Dec 8, 2003
    #1
    1. Advertising

  2. Tom Lee

    lostinet Guest

    <%#DataBinder.Eval(Container.DataItem,
    DataBinder.Eval(Container.DataItem,"PropertyName","{0}")
    )%>

    "Tom Lee" <> ????
    news:054c01c3bdd9$cc2956c0$...
    > Hi all,
    > I have the following problem and I cannot solve it. If
    > anyone can help me solve this problem.
    > I use the following code
    > <%#DataBinder.Eval(Container.DataItem, "Property")%>
    > to display Property from database. How do I dynamically
    > change the value "Property" to another one say "Name" to
    > display the Name from database or to any other variable
    > that I want.
    > Thanks.
    lostinet, Dec 9, 2003
    #2
    1. Advertising

  3. Tom Lee

    Chris Carter Guest

    Define a function and bind to that(assume your datasource is a DataView):

    public string GetDynamicValue(object dataItem)
    {
    DataRowView drv = dataItem As DataRowView;
    string fieldValue = "N/A";
    string fieldToReturn = "";
    if (somecondition)
    {
    fieldToReturn = "LastName";
    }
    else
    {
    fieldToReturn = "FirstName";
    }
    if (drv != null)
    {
    fieldValue = drv[fieldToReturn].ToString();
    }
    return fieldValue;
    }

    then in your script:

    <%# GetDynamicValue ( Container.DataItem ) %>

    if you're not sure what type your DataItem is, you can start with this:

    public string GetDynamicValue ( object dataItem )
    {
    return dataItem.ToString();
    }

    -chris
    "Tom Lee" <> wrote in message
    news:054c01c3bdd9$cc2956c0$...
    > Hi all,
    > I have the following problem and I cannot solve it. If
    > anyone can help me solve this problem.
    > I use the following code
    > <%#DataBinder.Eval(Container.DataItem, "Property")%>
    > to display Property from database. How do I dynamically
    > change the value "Property" to another one say "Name" to
    > display the Name from database or to any other variable
    > that I want.
    > Thanks.
    Chris Carter, Dec 9, 2003
    #3
    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. Lauchlan M
    Replies:
    1
    Views:
    7,215
    Lauchlan M
    Oct 15, 2003
  2. bg
    Replies:
    5
    Views:
    6,351
    Scott Allen
    Apr 16, 2004
  3. Ken Cox [Microsoft MVP]
    Replies:
    1
    Views:
    3,448
    Charlie@CBFC
    May 12, 2004
  4. Eric Newton
    Replies:
    3
    Views:
    9,355
    Brock Allen
    Apr 4, 2005
  5. Joe Rattz
    Replies:
    2
    Views:
    579
    Robert Koritnik
    Sep 10, 2004
Loading...

Share This Page