Adding <tr> from repeater's ItemDataBound Event

Posted by nemiss on Stack Overflow See other posts from Stack Overflow or by nemiss
Published on 2010-04-06T16:14:16Z Indexed on 2010/04/06 20:53 UTC
Read the original article Hit count: 272

Filed under:

My repeater's templates generate a table, where each item is a table row.
When a very very specific condition is met (itemdata), I want to add an additional row to the table from this event.

How can I do that?

protected void rptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Item ||
         e.Item.ItemType == ListItemType.AlternatingItem)
   {

        bool tmp = bool.Parse(DataBinder.Eval(e.Item.DataItem, "somedata").ToString());
        if (!tmp && e.Item.ItemIndex != 0)
        {
            //Add row after this item
        }

   }
}

I can use e.Item.Controls.Add() and add TableRow but for that I need to locate a table right?
How can I solve that?

UPDATE
I will explain now why I need this:

I am creating a sort of message board, where data entries are displayed in a tabled style.
The first items in the table are "important" items after those items, i want to add this row.

I could solved it using 2 repeaters, where the first repeater will be bounded to pinned items, and the second repeater will be bounded to refular items.
But I don't want to have to repeaters nor I want to complex the business logic for separating the fetched data to pinned and not-pinned collection.

I think the best opton is to do it "onfly", using one repeater and one datasource.

© Stack Overflow or respective owner

Related posts about ASP.NET