我试图使Repeater表可见= false

时间:2010-08-03 18:39:08

标签: c# vb.net repeater visible

我有一个文档管理系统,可以创建一个报告,显示拥有哪个文档的人。有些时候人们有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();

3 个答案:

答案 0 :(得分:1)

所以你需要做的就是检查你的数据是否为空 - 无论是在绑定之前,还是在转发器的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;
}

答案 1 :(得分:0)

在后面的代码中,在Repeater的ItemCreated事件中,您可以检查文档计数,并且只有在数据计数大于0的情况下才绑定转发器项目中的表。

答案 2 :(得分:0)

您可以完全像“rlb.usa”所说的那样,或者只用else替换else { collectorData.DataSource = null; collectorData.DataBind(); contactedData.DataSource = null; contactedData.DataBind(); } 部分:

{{1}}
相关问题