asp repeater databound

帅比萌擦擦* 提交于 2019-12-13 03:05:35

问题


I guys, isn't present databound event on asp repeater server control?

I just want to bind all my data, and at the end creates a new ItemTemplate and add it, but just when is all data binded


回答1:


I use this for calculating total hours in the collection. Even though I put it into the FooterTemplate, you should be able to get the point.

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


来源:https://stackoverflow.com/questions/3310574/asp-repeater-databound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!