注射直放站项目内表行 [英] Injecting table row inside repeater item

查看:85
本文介绍了注射直放站项目内表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图注入里面中继器项目,问题是,该行是在一个错误的位置产生的。结果
如果你试试这个简单的例子,你会看到rown下标2产生的,它应该在标签'1'产生。

为什么会发生?而如何解决这个问题?

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    INT []数组= {1,2,3,4,5};
    rpt.DataSource =阵列;
    rpt.DataBind();
}保护字符串_extraRowHtml;
保护无效rpt_ItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
   如果(e.Item.ItemType == || ListItemType.Item
          e.Item.ItemType == ListItemType.AlternatingItem)
  {
       INT TMP =((int)的e.Item.DataItem);
       _extraRowHtml = TMP == 1? < TR>< TD类= \\topicsRow \\合并单元格= \\100%\\>&主题LT; / TD>< / TR>中:的String.Empty; ;  }
}< ASP:直放站ID =RPT=服务器onitemdatabound =rpt_ItemDataBound>
    <&HeaderTemplate中GT;
       <表格的cellpadding =0像素CELLSPACING =0>
    < / HeaderTemplate中>
    <&ItemTemplate中GT;
      < TR风格=高度:50像素>
        &所述; TD>          < ASP:超链接ID =lnkTitle=服务器文本='<%#的Container.DataItem%GT;/>
         < / TD>
       < / TR>
       <%#_extraRowHtml%GT;
    < / ItemTemplate中>
  < FooterTempl
    < /表>
  < / FooterTemplate>
< / ASP:直放站>


解决方案

我个人认为,做一个更好的办法是就是更换:

 <&GT%#_extraRowHtml%;

 <%#GetExtraRow(的Container.DataItem)%GT;

然后在code后面执行:

 保护字符串GetExtraRow(对象数据)
{
    INT TMP =(int)的数据:
    返回_TMP == 1?
        < TR>< TD类= \\topicsRow \\合并单元格= \\100%\\>&主题LT; / TD>< / TR>中:
        的String.Empty;
}

然后,摆脱了 rpt_ItemDataBound 功能(和 onItemDataBound )。

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;
    rpt.DataBind();     
}

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">
    <HeaderTemplate>
       <table  cellpadding="0px" cellspacing="0">             
    </HeaderTemplate>            
    <ItemTemplate>     
      <tr style="height:50px">            
        <td>  

          <asp:HyperLink  ID="lnkTitle" runat="server" Text='<%# Container.DataItem%>'/>              
         </td>              
       </tr>
       <%# _extraRowHtml %>   
    </ItemTemplate>        
  <FooterTempl
    </table> 
  </FooterTemplate> 
</asp:Repeater>

解决方案

Personally I think a better way of doing is is to replace:

<%# _extraRowHtml %>

with

<%# 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>" : 
        string.Empty;
}

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

这篇关于注射直放站项目内表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆