【问题标题】:asp repeater databoundasp中继器数据绑定
【发布时间】:2010-07-22 15:29:14
【问题描述】:

伙计们,asp 转发器服务器控件上不存在数据绑定事件吗?

我只是想绑定我所有的数据,最后创建一个新的ItemTemplate并添加它,但是什么时候绑定所有数据

【问题讨论】:

    标签: .net asp.net repeater databound


    【解决方案1】:

    我用它来计算集合中的总小时数。即使我把它放在FooterTemplate 中,你也应该能明白这一点。

    <asp:Repeater ID="rptRecords" runat="server" OnItemDataBound="rptRecords_ItemDataBound">

    protected void rptRecords_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            int totalHours = 0;
    
            foreach (RepeaterItem item in ((Repeater)sender).Items)
            {
                Label lblRowHours = (Label)item.FindControl("lblHours");
                if (lblRowHours != null)
                    totalHours += Convert.ToInt32(lblRowHours.Text);
            }
    
            ((Label)e.Item.FindControl("lblHoursTotal")).Text = totalHours.ToString();
        }
    }
    

    【讨论】:

    • 谢谢,这就是我需要的 if (e.Item.ItemType == ListItemType.Footer) :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    相关资源
    最近更新 更多