Injecting table row inside repeater item

Total Post:104


 1346  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 %>  

  1. Re: Injecting table row inside repeater item

    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).

      Modified On Apr-05-2018 04:25:49 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.