Displaying databound values as members of a collection or array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Displaying databound values as members of a collection or array

    I am using databinding and the Repeater control to display the results of a
    database query. I normally use the DataBinder.Eval method for this, but in a
    scenario I am currently dealing with I would like to be able to do something
    like one of the following:


    If the value from the database is True then display 'Active', if it is False
    display 'Inactive'

    OR

    Use the value from the database as an index or key to get a value from an
    array, collection, or enumeration, which will be the displayed value


    I realize that both of these can easily be done using the ItemDataBound
    event, but since they are very simple operations I was wondering if there is
    a more efficient technique than calling ItemDataBound for every record. Any
    ideas? Thanks.

    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • sloan

    #2
    Re: Displaying databound values as members of a collection or array




    You can create a mini "display value" function on the page code behind.


    public string DisplayMyCoolVa lue( object theValue )
    {

    if (null== theValue)
    {
    return string.Empty;
    }

    bool b = Convert.ToBoole an(theValue);
    if(b)
    {
    return "Active";
    }
    return "Inactive";

    }


    notice the "theValue" goes in as on object. That's because of
    DataBinder.Eval .

    Now just take your DataBinder.Eval , and wrap the function call around
    (outside of) it.

    DisplayMyCoolVa lue ( DataBinder.Eval ("ItemActive " )

    You'll have to play with it a little, I'm coding from memory.





    "Nathan Sokalski" <nsokalski@kyle davidgroup.comw rote in message
    news:uG$4d6X$IH A.3756@TK2MSFTN GP03.phx.gbl...
    >I am using databinding and the Repeater control to display the results of a
    >database query. I normally use the DataBinder.Eval method for this, but in
    >a scenario I am currently dealing with I would like to be able to do
    >something like one of the following:
    >
    >
    If the value from the database is True then display 'Active', if it is
    False display 'Inactive'
    >
    OR
    >
    Use the value from the database as an index or key to get a value from an
    array, collection, or enumeration, which will be the displayed value
    >
    >
    I realize that both of these can easily be done using the ItemDataBound
    event, but since they are very simple operations I was wondering if there
    is a more efficient technique than calling ItemDataBound for every record.
    Any ideas? Thanks.
    >
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

    >

    Comment

    • sloan

      #3
      Re: Displaying databound values as members of a collection or array


      Here's the call to set the text of a label:

      Text='<%# DisplayMyCoolVa lue(DataBinder. Eval(Container,
      "DataItem.ItemA ctive") )%>'




      "sloan" <sloan@ipass.ne twrote in message
      news:OpBDQKY$IH A.1296@TK2MSFTN GP02.phx.gbl...
      >
      >
      >
      You can create a mini "display value" function on the page code behind.
      >
      >
      public string DisplayMyCoolVa lue( object theValue )
      {
      >
      if (null== theValue)
      {
      return string.Empty;
      }
      >
      bool b = Convert.ToBoole an(theValue);
      if(b)
      {
      return "Active";
      }
      return "Inactive";
      >
      }
      >
      >
      notice the "theValue" goes in as on object. That's because of
      DataBinder.Eval .
      >
      Now just take your DataBinder.Eval , and wrap the function call around
      (outside of) it.
      >
      DisplayMyCoolVa lue ( DataBinder.Eval ("ItemActive " )
      >
      You'll have to play with it a little, I'm coding from memory.
      >
      >
      >
      >
      >
      "Nathan Sokalski" <nsokalski@kyle davidgroup.comw rote in message
      news:uG$4d6X$IH A.3756@TK2MSFTN GP03.phx.gbl...
      >>I am using databinding and the Repeater control to display the results of
      >>a database query. I normally use the DataBinder.Eval method for this, but
      >>in a scenario I am currently dealing with I would like to be able to do
      >>something like one of the following:
      >>
      >>
      >If the value from the database is True then display 'Active', if it is
      >False display 'Inactive'
      >>
      >OR
      >>
      >Use the value from the database as an index or key to get a value from an
      >array, collection, or enumeration, which will be the displayed value
      >>
      >>
      >I realize that both of these can easily be done using the ItemDataBound
      >event, but since they are very simple operations I was wondering if there
      >is a more efficient technique than calling ItemDataBound for every
      >record. Any ideas? Thanks.
      >>
      >Nathan Sokalski
      >njsokalski@hotm ail.com
      >http://www.nathansokalski.com/
      >>
      >
      >

      Comment

      Working...