Controlling what is regarded as Item/AlternatingItem

Discussion in 'ASP .Net' started by K Viltersten, Oct 4, 2009.

  1. K Viltersten

    K Viltersten Guest

    I'm reworking a repeater that previously used

    if (e.Item.ItemType == ListItemType.Item)
    css += "plain";
    else
    css += "alter";

    Some of the rows will now be hidden, which
    creates the ugly appearance of several
    consecutive and visible rows to share the
    same css (e.g. alter).

    I need to manipulate the repeater to
    disregard certain rows upon binding the
    data. So to speak - skip a line.

    One way to do this would probably be a
    static flag, the status of which would
    change with every non-hidden row but that's
    a) ugly,
    b) non object oriented,
    c) blah-ish.

    Any suggestions?

    --
    Regards
    K Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.
    K Viltersten, Oct 4, 2009
    #1
    1. Advertising

  2. One thing I would look into is using the AlternatingItemTemplate. This uses
    the same DataSource as the ItemTemplate, but it allows you to specify a
    different template. Also, what are the conditions that determine which rows
    will be displayed and hidded? You may want to look into the ItemDataBound
    event for this, and set the desired CSS from inside the ItemDataBound event
    after determining whether you want to display or hide the row. Hopefully
    this helps.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "K Viltersten" <> wrote in message
    news:...
    > I'm reworking a repeater that previously used
    >
    > if (e.Item.ItemType == ListItemType.Item)
    > css += "plain";
    > else
    > css += "alter";
    >
    > Some of the rows will now be hidden, which creates the ugly appearance of
    > several consecutive and visible rows to share the same css (e.g. alter).
    >
    > I need to manipulate the repeater to disregard certain rows upon binding
    > the data. So to speak - skip a line.
    >
    > One way to do this would probably be a static flag, the status of which
    > would change with every non-hidden row but that's
    > a) ugly,
    > b) non object oriented,
    > c) blah-ish.
    >
    > Any suggestions?
    >
    > --
    > Regards
    > K Viltersten
    > ----------------------------------------
    > May all spammers die an agonizing death;
    > have no burial places; their souls be
    > chased by demons in Gehenna from one room
    > to another for all eternity and beyond.
    >
    Nathan Sokalski, Oct 4, 2009
    #2
    1. Advertising

  3. K Viltersten

    K Viltersten Guest

    SV: Controlling what is regarded as Item/AlternatingItem

    > One thing I would look into is using the
    > AlternatingItemTemplate. This uses the
    > same DataSource as the ItemTemplate, but
    > it allows you to specify a different
    > template.


    Well, that's what i'm using. Perhaps i should
    clarify the code a bit more.

    ListItemType t = e.Item.ItemType;
    if (t == ListItemType.AlternatingItem)
    css += "alter";
    else if (t == ListItemType.Item)
    css += "plain";

    > You may want to look into the ItemDataBound
    > event for this, and set the desired CSS
    > from inside the ItemDataBound event...


    The setup above IS ALREADY in the event
    handler for data binding. Where else could
    it be placed, anyway?

    So, the question is, as i expressed it in my
    original question, how one can manipulate
    the list item type of a given item, depending
    on the outcome of their predecessors and
    successors.

    Thank you.

    --

    Regards
    Konrad Viltersten
    --------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.
    K Viltersten, Oct 4, 2009
    #3
  4. First of all, since your code will ALWAYS give your ItemTemplate the css
    class "plain" and AlternatingItemTemplate the css class "alter", why are you
    doing it in the codebehind at all? I would have done something like the
    following:

    <asp:Repeater ID="repSample" runat="server">
    <ItemTemplate>
    <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
    CssClass="plain"/>
    </ItemTemplate>
    <AlternatingItemTemplate>
    <asp:Label ID="lblAlternatingItemContent" runat="server"
    Text="AlternatingItemTemplate Label" CssClass="alter"/>
    </AlternatingItemTemplate>
    </asp:Repeater>

    I just used Labels as example content, but the point is that the styles are
    different in the two templates without the need for anything in the
    codebehind.

    As for your question about manipulating an item based on other items, I
    would suggest doing something that would involve the following:

    In the PreRender event, use the Items property of the Repeater to view and
    modify any items you wish to modify.

    Another approach that you could use would be to, in the ItemDataBound use
    the e.Item.ItemIndex property to get any necessary data from the Repeater's
    DataSource. To do this, you will use when getting the data from the
    Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1 as the
    index to get data about the previous item or e.Item.ItemIndex+1 as the index
    to get the next item.

    Hopefully this helps. Because I have not seen your code and do not know what
    the goal of your project is, I cannot say whether or not there is another or
    better way, but when using databinding it is usually best to try to avoid
    basing the formatting of one item on another item. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "K Viltersten" <> wrote in message
    news:...
    >> One thing I would look into is using the AlternatingItemTemplate. This
    >> uses the same DataSource as the ItemTemplate, but it allows you to
    >> specify a different template.

    >
    > Well, that's what i'm using. Perhaps i should
    > clarify the code a bit more.
    >
    > ListItemType t = e.Item.ItemType;
    > if (t == ListItemType.AlternatingItem)
    > css += "alter";
    > else if (t == ListItemType.Item)
    > css += "plain";
    >
    >> You may want to look into the ItemDataBound event for this, and set the
    >> desired CSS from inside the ItemDataBound event...

    >
    > The setup above IS ALREADY in the event handler for data binding. Where
    > else could
    > it be placed, anyway?
    >
    > So, the question is, as i expressed it in my
    > original question, how one can manipulate the list item type of a given
    > item, depending
    > on the outcome of their predecessors and successors.
    >
    > Thank you.
    >
    > --
    >
    > Regards
    > Konrad Viltersten
    > --------------------------------
    > May all spammers die an agonizing death;
    > have no burial places; their souls be
    > chased by demons in Gehenna from one room
    > to another for all eternity and beyond.
    Nathan Sokalski, Oct 5, 2009
    #4
  5. K Viltersten

    K Viltersten Guest

    As i mentioned in the original post, some of
    the rows will be hidden (regardless of them
    being styled to plain/alter.

    So, by only adding the style the way you
    described, i might get to SEE only plain
    rows (if the alternating happen to be hidden
    because of the new conditions).

    Index will not work either, for the same
    reason.

    I went for boolean flag that changes the
    state for each data bind event fired, except
    for those that are hidden. I'm not very
    satisfied with that solution, though.

    Any suggestion to that?

    Thanks.

    --
    Regards
    K Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.





    "Nathan Sokalski" <> wrote in message
    news:%...
    > First of all, since your code will ALWAYS give your ItemTemplate the css
    > class "plain" and AlternatingItemTemplate the css class "alter", why are
    > you doing it in the codebehind at all? I would have done something like
    > the following:
    >
    > <asp:Repeater ID="repSample" runat="server">
    > <ItemTemplate>
    > <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
    > CssClass="plain"/>
    > </ItemTemplate>
    > <AlternatingItemTemplate>
    > <asp:Label ID="lblAlternatingItemContent" runat="server"
    > Text="AlternatingItemTemplate Label" CssClass="alter"/>
    > </AlternatingItemTemplate>
    > </asp:Repeater>
    >
    > I just used Labels as example content, but the point is that the styles
    > are different in the two templates without the need for anything in the
    > codebehind.
    >
    > As for your question about manipulating an item based on other items, I
    > would suggest doing something that would involve the following:
    >
    > In the PreRender event, use the Items property of the Repeater to view and
    > modify any items you wish to modify.
    >
    > Another approach that you could use would be to, in the ItemDataBound use
    > the e.Item.ItemIndex property to get any necessary data from the
    > Repeater's DataSource. To do this, you will use when getting the data from
    > the Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1
    > as the index to get data about the previous item or e.Item.ItemIndex+1 as
    > the index to get the next item.
    >
    > Hopefully this helps. Because I have not seen your code and do not know
    > what the goal of your project is, I cannot say whether or not there is
    > another or better way, but when using databinding it is usually best to
    > try to avoid basing the formatting of one item on another item. Good Luck!
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "K Viltersten" <> wrote in message
    > news:...
    >>> One thing I would look into is using the AlternatingItemTemplate. This
    >>> uses the same DataSource as the ItemTemplate, but it allows you to
    >>> specify a different template.

    >>
    >> Well, that's what i'm using. Perhaps i should
    >> clarify the code a bit more.
    >>
    >> ListItemType t = e.Item.ItemType;
    >> if (t == ListItemType.AlternatingItem)
    >> css += "alter";
    >> else if (t == ListItemType.Item)
    >> css += "plain";
    >>
    >>> You may want to look into the ItemDataBound event for this, and set the
    >>> desired CSS from inside the ItemDataBound event...

    >>
    >> The setup above IS ALREADY in the event handler for data binding. Where
    >> else could
    >> it be placed, anyway?
    >>
    >> So, the question is, as i expressed it in my
    >> original question, how one can manipulate the list item type of a given
    >> item, depending
    >> on the outcome of their predecessors and successors.
    >>
    >> Thank you.
    >>
    >> --
    >>
    >> Regards
    >> Konrad Viltersten
    >> --------------------------------
    >> May all spammers die an agonizing death;
    >> have no burial places; their souls be
    >> chased by demons in Gehenna from one room
    >> to another for all eternity and beyond.

    >
    >
    K Viltersten, Oct 5, 2009
    #5
  6. K Viltersten

    musosdev Guest

    This might be way off, but could you not create a DataSet that's generated
    from your data + a Hidden flag, and then DataBind from that, so the only
    things that get sent to the Repeater are the actual things you want to show?

    I'm not sure of the code to do it off-hand, but that's how I'd approach it.

    "K Viltersten" wrote:

    > As i mentioned in the original post, some of
    > the rows will be hidden (regardless of them
    > being styled to plain/alter.
    >
    > So, by only adding the style the way you
    > described, i might get to SEE only plain
    > rows (if the alternating happen to be hidden
    > because of the new conditions).
    >
    > Index will not work either, for the same
    > reason.
    >
    > I went for boolean flag that changes the
    > state for each data bind event fired, except
    > for those that are hidden. I'm not very
    > satisfied with that solution, though.
    >
    > Any suggestion to that?
    >
    > Thanks.
    >
    > --
    > Regards
    > K Viltersten
    > ----------------------------------------
    > May all spammers die an agonizing death;
    > have no burial places; their souls be
    > chased by demons in Gehenna from one room
    > to another for all eternity and beyond.
    >
    >
    >
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:%...
    > > First of all, since your code will ALWAYS give your ItemTemplate the css
    > > class "plain" and AlternatingItemTemplate the css class "alter", why are
    > > you doing it in the codebehind at all? I would have done something like
    > > the following:
    > >
    > > <asp:Repeater ID="repSample" runat="server">
    > > <ItemTemplate>
    > > <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
    > > CssClass="plain"/>
    > > </ItemTemplate>
    > > <AlternatingItemTemplate>
    > > <asp:Label ID="lblAlternatingItemContent" runat="server"
    > > Text="AlternatingItemTemplate Label" CssClass="alter"/>
    > > </AlternatingItemTemplate>
    > > </asp:Repeater>
    > >
    > > I just used Labels as example content, but the point is that the styles
    > > are different in the two templates without the need for anything in the
    > > codebehind.
    > >
    > > As for your question about manipulating an item based on other items, I
    > > would suggest doing something that would involve the following:
    > >
    > > In the PreRender event, use the Items property of the Repeater to view and
    > > modify any items you wish to modify.
    > >
    > > Another approach that you could use would be to, in the ItemDataBound use
    > > the e.Item.ItemIndex property to get any necessary data from the
    > > Repeater's DataSource. To do this, you will use when getting the data from
    > > the Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1
    > > as the index to get data about the previous item or e.Item.ItemIndex+1 as
    > > the index to get the next item.
    > >
    > > Hopefully this helps. Because I have not seen your code and do not know
    > > what the goal of your project is, I cannot say whether or not there is
    > > another or better way, but when using databinding it is usually best to
    > > try to avoid basing the formatting of one item on another item. Good Luck!
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.nathansokalski.com/
    > >
    > > "K Viltersten" <> wrote in message
    > > news:...
    > >>> One thing I would look into is using the AlternatingItemTemplate. This
    > >>> uses the same DataSource as the ItemTemplate, but it allows you to
    > >>> specify a different template.
    > >>
    > >> Well, that's what i'm using. Perhaps i should
    > >> clarify the code a bit more.
    > >>
    > >> ListItemType t = e.Item.ItemType;
    > >> if (t == ListItemType.AlternatingItem)
    > >> css += "alter";
    > >> else if (t == ListItemType.Item)
    > >> css += "plain";
    > >>
    > >>> You may want to look into the ItemDataBound event for this, and set the
    > >>> desired CSS from inside the ItemDataBound event...
    > >>
    > >> The setup above IS ALREADY in the event handler for data binding. Where
    > >> else could
    > >> it be placed, anyway?
    > >>
    > >> So, the question is, as i expressed it in my
    > >> original question, how one can manipulate the list item type of a given
    > >> item, depending
    > >> on the outcome of their predecessors and successors.
    > >>
    > >> Thank you.
    > >>
    > >> --
    > >>
    > >> Regards
    > >> Konrad Viltersten
    > >> --------------------------------
    > >> May all spammers die an agonizing death;
    > >> have no burial places; their souls be
    > >> chased by demons in Gehenna from one room
    > >> to another for all eternity and beyond.

    > >
    > >

    >
    >
    musosdev, Oct 5, 2009
    #6
  7. What CSS are you adding to the items to specify whether they are hidden or
    not? Regardless of what other styling there is, if you set the CSS display
    property to none, then it should be hidden. But here is a question that I
    just want to make sure I have a clear answer on right now: Is your problem
    in finding/accessing the items you want to modify, or is the problem in
    figuring out how to style them to get a final product that looks the way you
    want? I think it might be useful to everyone here in the newsgroup (at least
    I would find it useful) if you showed us a little more code, as well as a
    sample of what you want the final output to look like. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "K Viltersten" <> wrote in message
    news:...
    > As i mentioned in the original post, some of
    > the rows will be hidden (regardless of them
    > being styled to plain/alter.
    >
    > So, by only adding the style the way you
    > described, i might get to SEE only plain
    > rows (if the alternating happen to be hidden
    > because of the new conditions).
    >
    > Index will not work either, for the same
    > reason.
    >
    > I went for boolean flag that changes the
    > state for each data bind event fired, except
    > for those that are hidden. I'm not very
    > satisfied with that solution, though.
    >
    > Any suggestion to that?
    >
    > Thanks.
    >
    > --
    > Regards
    > K Viltersten
    > ----------------------------------------
    > May all spammers die an agonizing death;
    > have no burial places; their souls be
    > chased by demons in Gehenna from one room
    > to another for all eternity and beyond.
    >
    >
    >
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:%...
    >> First of all, since your code will ALWAYS give your ItemTemplate the css
    >> class "plain" and AlternatingItemTemplate the css class "alter", why are
    >> you doing it in the codebehind at all? I would have done something like
    >> the following:
    >>
    >> <asp:Repeater ID="repSample" runat="server">
    >> <ItemTemplate>
    >> <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
    >> CssClass="plain"/>
    >> </ItemTemplate>
    >> <AlternatingItemTemplate>
    >> <asp:Label ID="lblAlternatingItemContent" runat="server"
    >> Text="AlternatingItemTemplate Label" CssClass="alter"/>
    >> </AlternatingItemTemplate>
    >> </asp:Repeater>
    >>
    >> I just used Labels as example content, but the point is that the styles
    >> are different in the two templates without the need for anything in the
    >> codebehind.
    >>
    >> As for your question about manipulating an item based on other items, I
    >> would suggest doing something that would involve the following:
    >>
    >> In the PreRender event, use the Items property of the Repeater to view
    >> and modify any items you wish to modify.
    >>
    >> Another approach that you could use would be to, in the ItemDataBound use
    >> the e.Item.ItemIndex property to get any necessary data from the
    >> Repeater's DataSource. To do this, you will use when getting the data
    >> from the Repeater's DataSource, you will do stuff like use
    >> e.Item.ItemIndex-1 as the index to get data about the previous item or
    >> e.Item.ItemIndex+1 as the index to get the next item.
    >>
    >> Hopefully this helps. Because I have not seen your code and do not know
    >> what the goal of your project is, I cannot say whether or not there is
    >> another or better way, but when using databinding it is usually best to
    >> try to avoid basing the formatting of one item on another item. Good
    >> Luck!
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "K Viltersten" <> wrote in message
    >> news:...
    >>>> One thing I would look into is using the AlternatingItemTemplate. This
    >>>> uses the same DataSource as the ItemTemplate, but it allows you to
    >>>> specify a different template.
    >>>
    >>> Well, that's what i'm using. Perhaps i should
    >>> clarify the code a bit more.
    >>>
    >>> ListItemType t = e.Item.ItemType;
    >>> if (t == ListItemType.AlternatingItem)
    >>> css += "alter";
    >>> else if (t == ListItemType.Item)
    >>> css += "plain";
    >>>
    >>>> You may want to look into the ItemDataBound event for this, and set the
    >>>> desired CSS from inside the ItemDataBound event...
    >>>
    >>> The setup above IS ALREADY in the event handler for data binding. Where
    >>> else could
    >>> it be placed, anyway?
    >>>
    >>> So, the question is, as i expressed it in my
    >>> original question, how one can manipulate the list item type of a given
    >>> item, depending
    >>> on the outcome of their predecessors and successors.
    >>>
    >>> Thank you.
    >>>
    >>> --
    >>>
    >>> Regards
    >>> Konrad Viltersten
    >>> --------------------------------
    >>> May all spammers die an agonizing death;
    >>> have no burial places; their souls be
    >>> chased by demons in Gehenna from one room
    >>> to another for all eternity and beyond.

    >>
    >>

    >
    Nathan Sokalski, Oct 5, 2009
    #7
    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. ssoss

    Display Related Item or Add Item

    ssoss, Sep 17, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    467
    ssoss
    Sep 19, 2003
  2. Beffmans

    AlternatingItem Style in asp:table

    Beffmans, Jul 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    423
    =?Utf-8?B?U2l2YSBN?=
    Jul 20, 2005
  3. DebonairDC

    AlternatingItem without repeating code

    DebonairDC, Nov 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    336
    DebonairDC
    Nov 11, 2005
  4. bpd
    Replies:
    0
    Views:
    792
  5. kidpurple

    OnItemDatabound requires Item or AlternatingItem and Item?

    kidpurple, Nov 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    255
    kidpurple
    Nov 2, 2004
Loading...

Share This Page