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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Lee

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

    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.E val(Container.D ataItem, "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

    #2
    Re: Passing value into DataBinder.Eval (Container.Data Item, &quot;Property& quot;)

    <%#DataBinder.E val(Container.D ataItem,
    DataBinder.Eval (Container.Data Item,"PropertyN ame","{0}")
    )%>

    "Tom Lee" <anonymous@disc ussions.microso ft.com> ????
    news:054c01c3bd d9$cc2956c0$a10 1280a@phx.gbl.. .[color=blue]
    > 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.E val(Container.D ataItem, "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.[/color]


    Comment

    • Chris Carter

      #3
      Re: Passing value into DataBinder.Eval (Container.Data Item, &quot;Property& quot;)

      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.DataI tem ) %>

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

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

      -chris
      "Tom Lee" <anonymous@disc ussions.microso ft.com> wrote in message
      news:054c01c3bd d9$cc2956c0$a10 1280a@phx.gbl.. .[color=blue]
      > 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.E val(Container.D ataItem, "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.[/color]


      Comment

      Working...