中继器中的ASP .NET中继器

ASP .NET Repeater inside Repeater
2020-11-21
  •  译文(汉语)
  •  原文(英语)

我正在尝试在* .aspx页的父中继内创建子中继.

我有一个小问题,我不知道该如何解决.(我将在附图中显示)

中继器中的ASP .NET中继器

代码如下:

<asp:Panel ID="pnlUserActionSummary" runat="server" Visible="false">
    <h3><b>User Actions</b></h3>
    <hr/>

    <asp:Repeater id="UserActionDetailsRepeader" runat="server" OnItemDataBound="UserActionDetailsRepeadetItemBound">
        <ItemTemplate>
            <h3><b><asp:Literal ID="lit1" runat="server" Text='<%# Eval("PhaseDisplayName") %>'></asp:Literal></b></h3>

            <asp:Literal ID="lu1" runat="server" Text="Started On: "></asp:Literal> 
            <asp:Literal ID="lu2" runat="server" Text='<%#Eval("PhaseStartedOn")%>'></asp:Literal>

            <br/>
            <asp:Literal ID="lu3" runat="server" Text="Status: "></asp:Literal> 
            <asp:Literal ID="lu4" runat="server" Text='<%# Eval("PhaseStatus") %>'></asp:Literal>

            <br/>
            <br/>                                

            <asp:Repeater ID="TaskDetailsRepeater" runat="server">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th><asp:Literal ID="l1" runat="server" Text="User"></asp:Literal></th>
                                <th><asp:Literal ID="l2" runat="server" Text="Status"></asp:Literal></th>
                                <th><asp:Literal ID="l3" runat="server" Text="Completed On"></asp:Literal></th>
                                <th><asp:Literal ID="l4" runat="server" Text="Comment"></asp:Literal></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr runat="server" id="itemPlaceholder">
                            </tr>
                        </tbody>
                    </table>
                </HeaderTemplate>

                <ItemTemplate>
                    <tr>
                        <td><%#DataBinder.Eval(Container.DataItem, "UserName")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Status")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "CompletedOn")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Comment")%></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

            <br />
            <br />
        </ItemTemplate>
    </asp:Repeater>

    <br />
</asp:Panel>

您能否建议我如何更改代码以拥有真正的表格,而不是简单的一行.

我绑定的集合:

    private void PlaceToBindParentDataSource()
    {        
        UserActionDetailsRepeader.DataSource = UserActions;
        UserActionDetailsRepeader.DataBind();
    }        

    protected void UserActionDetailsRepeadetItemBound(object sender, RepeaterItemEventArgs args)
    {            
        Repeater childRepeater = (Repeater)args.Item.FindControl("TaskDetailsRepeater");

        var boundItem = (UserActionsDetails)args.Item.DataItem;
        var userAction = UserActions.FirstOrDefault(x => x.Key.Equals(boundItem.Key));
        var itemTaskDetails = userAction.TaskDetails;

        childRepeater.DataSource = itemTaskDetails;
        childRepeater.DataBind();              
    }

    protected List<UserActionsDetails> UserActions;

    public class UserActionsDetails
    {
        public Guid Key { get; set; }
        public string PhaseDisplayName { get; set; }
        public string PhaseStatus { get; set; }
        public string PhaseStartedOn { get; set; }
        public List<TaskDetails> TaskDetails { get; set; }
    }

    public class TaskDetails
    {
        public string UserName { get; set; }
        public string Status { get; set; }
        public string CompletedOn { get; set; }
        public string Comment { get; set; }
    }  

谢谢.

解决过程1

如果您没有<tbody>丢失,HeaderTemplate并添加了一个FooterTemplate可以将其关闭的表,它将可以正常工作.

 <asp:Repeater ID="TaskDetailsRepeater" runat="server">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th><asp:Literal ID="l1" runat="server" Text="User"></asp:Literal></th>
                                <th><asp:Literal ID="l2" runat="server" Text="Status"></asp:Literal></th>
                                <th><asp:Literal ID="l3" runat="server" Text="Completed On"></asp:Literal></th>
                                <th><asp:Literal ID="l4" runat="server" Text="Comment"></asp:Literal></th>
                            </tr>
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%#DataBinder.Eval(Container.DataItem, "UserName")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Status")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "CompletedOn")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Comment")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </tbody>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
速聊1:
谢谢.你是对的.我只是在玩桌子的Cosing标签.然后我将其移至FooterTemplate并得到了结果.之后,我找到了您的答案.非常感谢你!

I am trying to create a child Repeater inside of a parent Repeater in an *.aspx page.

I have a small problem which i can't figure out how to resolve. (I will show in the attached image)

ASP .NET Repeater inside Repeater

The code is bellow:

<asp:Panel ID="pnlUserActionSummary" runat="server" Visible="false">
    <h3><b>User Actions</b></h3>
    <hr/>

    <asp:Repeater id="UserActionDetailsRepeader" runat="server" OnItemDataBound="UserActionDetailsRepeadetItemBound">
        <ItemTemplate>
            <h3><b><asp:Literal ID="lit1" runat="server" Text='<%# Eval("PhaseDisplayName") %>'></asp:Literal></b></h3>

            <asp:Literal ID="lu1" runat="server" Text="Started On: "></asp:Literal> 
            <asp:Literal ID="lu2" runat="server" Text='<%#Eval("PhaseStartedOn")%>'></asp:Literal>

            <br/>
            <asp:Literal ID="lu3" runat="server" Text="Status: "></asp:Literal> 
            <asp:Literal ID="lu4" runat="server" Text='<%# Eval("PhaseStatus") %>'></asp:Literal>

            <br/>
            <br/>                                

            <asp:Repeater ID="TaskDetailsRepeater" runat="server">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th><asp:Literal ID="l1" runat="server" Text="User"></asp:Literal></th>
                                <th><asp:Literal ID="l2" runat="server" Text="Status"></asp:Literal></th>
                                <th><asp:Literal ID="l3" runat="server" Text="Completed On"></asp:Literal></th>
                                <th><asp:Literal ID="l4" runat="server" Text="Comment"></asp:Literal></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr runat="server" id="itemPlaceholder">
                            </tr>
                        </tbody>
                    </table>
                </HeaderTemplate>

                <ItemTemplate>
                    <tr>
                        <td><%#DataBinder.Eval(Container.DataItem, "UserName")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Status")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "CompletedOn")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Comment")%></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

            <br />
            <br />
        </ItemTemplate>
    </asp:Repeater>

    <br />
</asp:Panel>

Can you suggest me please how can I change the code in order to have a real table, not a simple line.

The collections I bind:

    private void PlaceToBindParentDataSource()
    {        
        UserActionDetailsRepeader.DataSource = UserActions;
        UserActionDetailsRepeader.DataBind();
    }        

    protected void UserActionDetailsRepeadetItemBound(object sender, RepeaterItemEventArgs args)
    {            
        Repeater childRepeater = (Repeater)args.Item.FindControl("TaskDetailsRepeater");

        var boundItem = (UserActionsDetails)args.Item.DataItem;
        var userAction = UserActions.FirstOrDefault(x => x.Key.Equals(boundItem.Key));
        var itemTaskDetails = userAction.TaskDetails;

        childRepeater.DataSource = itemTaskDetails;
        childRepeater.DataBind();              
    }

    protected List<UserActionsDetails> UserActions;

    public class UserActionsDetails
    {
        public Guid Key { get; set; }
        public string PhaseDisplayName { get; set; }
        public string PhaseStatus { get; set; }
        public string PhaseStartedOn { get; set; }
        public List<TaskDetails> TaskDetails { get; set; }
    }

    public class TaskDetails
    {
        public string UserName { get; set; }
        public string Status { get; set; }
        public string CompletedOn { get; set; }
        public string Comment { get; set; }
    }  

Thanks.

Solutions1

If you leave <tbody> unlosed in HeaderTemplate and add a FooterTemplate that closes it and the table it should work.

 <asp:Repeater ID="TaskDetailsRepeater" runat="server">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th><asp:Literal ID="l1" runat="server" Text="User"></asp:Literal></th>
                                <th><asp:Literal ID="l2" runat="server" Text="Status"></asp:Literal></th>
                                <th><asp:Literal ID="l3" runat="server" Text="Completed On"></asp:Literal></th>
                                <th><asp:Literal ID="l4" runat="server" Text="Comment"></asp:Literal></th>
                            </tr>
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%#DataBinder.Eval(Container.DataItem, "UserName")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Status")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "CompletedOn")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem, "Comment")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </tbody>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
Talk1:
Thanks. You're right. I just was playing with the Cosing tag of the Table. And i moved it to a FooterTemplate and i got the result. After that i found your answer. Thank you very much!
转载于:https://stackoverflow.com/questions/28361526/asp-net-repeater-inside-repeater

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入