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
(E-Mail Removed)
http://www.nathansokalski.com/
"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> 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.