Repeater question

Discussion in 'ASP .Net' started by SpaceMarine, Dec 12, 2008.

  1. SpaceMarine

    SpaceMarine Guest

    hello,

    i have an ASPX page where i bind a datasource to a Repeater. i then
    render stuff in my <ItemTemplate> like so:

    <td>
    <%#DataBinder.Eval(Container.DataItem, "FirstName")%>,
    <%#DataBinder.Eval(Container.DataItem, "LastName")%>
    </td>

    ....thats cool, unless the above Eval()s are empty -- in which case you
    end up w/ a silly-looking "," and no names.

    so i want to write a function to evaluate multiple values in the
    DataItem at run-time. my question is -- what can i pass into this
    function in order to do this? something like this:

    <td>
    <%= MyFunction(Container) %>
    </td>

    public function MyFunction(DataItem item)
    {
    string returnValue = string.empty;

    //do some string analysis on the passed-in item. if both names
    exist, return them formatted as i like

    return returnValue;
    }


    ....the above doesnt seem quote right.

    can anyone assist?


    thanks!
    matt
    SpaceMarine, Dec 12, 2008
    #1
    1. Advertising

  2. SpaceMarine

    SpaceMarine Guest

    typo in my OP - the function would return a type "string", of course..
    SpaceMarine, Dec 12, 2008
    #2
    1. Advertising

  3. On Sat, 13 Dec 2008 00:08:58 +0100, SpaceMarine
    <> wrote:

    > ...the above doesnt seem quote right.


    The ASP.NET idiosyncratic way of solving this task would probably be:

    1. Declare a Literal control within the body of your Repeater markup.

    2. Attach a new method to handle the ItemDataBound event of the Repeater.

    a) Read data from e.Item.DataItem and do the computations and
    comparisons needed to build the string you want to display.

    b) Use e.Item.FindControl("myLiteral") to get a reference to the
    literal control, cast it, and assign its new Text value.

    This might not be the simplest way to solve the task, but I believe this
    is how you supposed to do it in ASP.NET :)

    --
    Joern Schou-Rode
    http://malamute.dk/
    Joern Schou-Rode, Dec 13, 2008
    #3
  4. SpaceMarine

    gerry Guest

    ....

    <%# MyFunction( Container.DataItem )%>

    ....



    public function MyFunction(object item)
    {

    MyObject mo = item as MyObject;

    ...

    }







    "SpaceMarine" <> wrote in message
    news:...
    > hello,
    >
    > i have an ASPX page where i bind a datasource to a Repeater. i then
    > render stuff in my <ItemTemplate> like so:
    >
    > <td>
    > <%#DataBinder.Eval(Container.DataItem, "FirstName")%>,
    > <%#DataBinder.Eval(Container.DataItem, "LastName")%>
    > </td>
    >
    > ...thats cool, unless the above Eval()s are empty -- in which case you
    > end up w/ a silly-looking "," and no names.
    >
    > so i want to write a function to evaluate multiple values in the
    > DataItem at run-time. my question is -- what can i pass into this
    > function in order to do this? something like this:
    >
    > <td>
    > <%= MyFunction(Container) %>
    > </td>
    >
    > public function MyFunction(DataItem item)
    > {
    > string returnValue = string.empty;
    >
    > //do some string analysis on the passed-in item. if both names
    > exist, return them formatted as i like
    >
    > return returnValue;
    > }
    >
    >
    > ...the above doesnt seem quote right.
    >
    > can anyone assist?
    >
    >
    > thanks!
    > matt
    gerry, Dec 15, 2008
    #4
  5. SpaceMarine

    SpaceMarine Guest

    thanks guys
    SpaceMarine, Dec 20, 2008
    #5
    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. Replies:
    0
    Views:
    853
  2. Replies:
    0
    Views:
    2,878
  3. Replies:
    1
    Views:
    7,019
    Karl Seguin
    Aug 10, 2005
  4. uncensored
    Replies:
    0
    Views:
    813
    uncensored
    Oct 25, 2006
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    205
    Microsoft
    Aug 21, 2006
Loading...

Share This Page