Home > DeveloperSection > Forums > Injecting table row inside repeater item
marcel ethan
marcel ethan

Total Post:105

Posted on    August-27-2014 1:50 AM


 1 Reply(s)
 891  View(s)
Rate this:

I am trying to inject inside repeaters items, the problem is that the row is generated in a wrong location.

If you try this simple example, you will see that the rown is generated under label '2' as it should be generated under label '1'.

Why does it happen? And how to fix that?

protected void Page_Load(object sender, EventArgs e)


    int [] array = {1,2,3,4,5};

    rpt.DataSource = array;



protected string _extraRowHtml;

protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)


   if (e.Item.ItemType == ListItemType.Item ||

          e.Item.ItemType == ListItemType.AlternatingItem)


       int tmp = ((int)e.Item.DataItem);

       _extraRowHtml = tmp == 1 ? "<tr><td class=\"topicsRow\" colspan=\"100%\"> Topics </td></tr>" : string.Empty; ;               



<asp:Repeater ID="rpt" runat="server" onitemdatabound="rpt_ItemDataBound">


       <table  cellpadding="0px" cellspacing="0">            



      <tr style="height:50px">           


          <asp:HyperLink  ID="lnkTitle" runat="server" Text='<%# Container.DataItem%>'/>             



       <%# _extraRowHtml %>  






Sumit Kesarwani

Total Post:378

Posted on    August-27-2014 3:02 AM

Hi Marcel,


<%# _extraRowHtml %>


<%# GetExtraRow(Container.DataItem) %>

then in your code behind implement:

protected string GetExtraRow(object Data)


    int tmp = (int) Data:

    return _tmp == 1 ?

        "<tr><td class=\"topicsRow\" colspan=\"100%\"> Topics </td></tr>" :



Then and get rid of the rpt_ItemDataBound function (and the onItemDataBound).

Don't want to miss updates? Please click the below button!

Follow MindStick