我试图使中继器表可见= false

发布于 2024-09-12 16:15:04 字数 1758 浏览 11 评论 0原文

我有一个文档管理系统,它创建一个报告,显示拥有哪个文档的人。有时人们有 0 个文档,在这种情况下,我希望该人的转发器表不可见。我环顾了一段时间,但运气不佳,也许是因为我是新人,也许是因为我还没有找到答案。

我有嵌套在中继器内的中继器,但如果第一个中继器不可见,其余的应该跟随。

.aspx 文件

                    <h3> <%# DataBinder.Eval(Container.DataItem, "FullNm") %></h3>
                    <table ID="CollectorTable" runat="server" class="report-totals">
                        <tr>
                            <th>Total Collected:</th>
                            <td><asp:Literal ID="CollectorTotalCollected" runat="server" /></td>

                            <td class="report-totals-spacer"></td>

                            <th>Total Contacted:</th>
                            <td><asp:Literal ID="CollectorTotalContacted" runat="server" /></td>

                            <td class="report-totals-spacer"></td>

                            <th></th>
                            <td></td>
                        </tr>
                    </table>
               // etc....

代码隐藏

        // ...pull totals
        Control CollectorRepeater = new Control();
        CollectorRepeater = (Control)e.Item.FindControl("CollectorRepeater");
        CollectorRepeater.Visible = false;

        Repeater collectorData = (Repeater)item.FindControl("CollectedTableRepeater");
        collectorData.DataSource = collectedDocuments;
        collectorData.DataBind();

        Repeater contactedData = (Repeater)item.FindControl("ContactedTableRepeater");
        contactedData.DataSource = contactedDocuments;
        contactedData.DataBind();

I have a document management system which creates a report showing people who own which document. There are times where people have 0 documents and in that case I would like the repeater table for that person to not be visible. I have looked around for a while and have not had much luck, maybe its because I am new or maybe its because I havent found my answer.

I have repeaters nested inside repeaters but if the first repeater is not visible the rest should follow.

aspx file

                    <h3> <%# DataBinder.Eval(Container.DataItem, "FullNm") %></h3>
                    <table ID="CollectorTable" runat="server" class="report-totals">
                        <tr>
                            <th>Total Collected:</th>
                            <td><asp:Literal ID="CollectorTotalCollected" runat="server" /></td>

                            <td class="report-totals-spacer"></td>

                            <th>Total Contacted:</th>
                            <td><asp:Literal ID="CollectorTotalContacted" runat="server" /></td>

                            <td class="report-totals-spacer"></td>

                            <th></th>
                            <td></td>
                        </tr>
                    </table>
               // etc....

Code Behind

        // ...pull totals
        Control CollectorRepeater = new Control();
        CollectorRepeater = (Control)e.Item.FindControl("CollectorRepeater");
        CollectorRepeater.Visible = false;

        Repeater collectorData = (Repeater)item.FindControl("CollectedTableRepeater");
        collectorData.DataSource = collectedDocuments;
        collectorData.DataBind();

        Repeater contactedData = (Repeater)item.FindControl("ContactedTableRepeater");
        contactedData.DataSource = contactedDocuments;
        contactedData.DataBind();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苦妄 2024-09-19 16:15:04

因此,您需要做的就是检查数据是否为空 - 在绑定数据之前或在中继器的 OnDataBinding 事件上,并在适当的情况下隐藏中继器。

Repeater collectorData = (Repeater)item.FindControl("CollectedTableRepeater1");
Repeater contactedData = (Repeater)item.FindControl("ContactedTableRepeater2");
if( collectedDocuments.Tables[0].Rows.Count > 0 ){
        //if there is data(more than 0 rows), bind it
        collectorData.DataSource = collectedDocuments;
        collectorData.DataBind();

        contactedData.DataSource = contactedDocuments;
        contactedData.DataBind();
} else {
        collectorData.Visible = False;
        //optional display "No data found" message
        contactedData.Visible = False;
}

So all you need to do is check if your data is empty - either before you bind it, or on a repeater's OnDataBinding event, and hide the repeaters if appropriate.

Repeater collectorData = (Repeater)item.FindControl("CollectedTableRepeater1");
Repeater contactedData = (Repeater)item.FindControl("ContactedTableRepeater2");
if( collectedDocuments.Tables[0].Rows.Count > 0 ){
        //if there is data(more than 0 rows), bind it
        collectorData.DataSource = collectedDocuments;
        collectorData.DataBind();

        contactedData.DataSource = contactedDocuments;
        contactedData.DataBind();
} else {
        collectorData.Visible = False;
        //optional display "No data found" message
        contactedData.Visible = False;
}
无声静候 2024-09-19 16:15:04

在后面的代码中,在中继器的 ItemCreated 事件您可以检查文档计数,并且仅当数据计数大于 0 时才将表绑定到重复器项中。

In the code behind, in the Repeater's ItemCreated event you can do a check for the document count, and only bind the table within the repeater item it if the count for the data is more than 0.

能怎样 2024-09-19 16:15:04

您可以完全像“rlb.usa”所说的那样,或者将 else 部分替换为:

else {
        collectorData.DataSource = null;
        collectorData.DataBind();

        contactedData.DataSource = null;
        contactedData.DataBind();
}

You can do exactly like "rlb.usa" said or just replace the else part with:

else {
        collectorData.DataSource = null;
        collectorData.DataBind();

        contactedData.DataSource = null;
        contactedData.DataBind();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文