gds03
gds03

Reputation: 1379

asp repeater databound

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

Upvotes: 0

Views: 7926

Answers (1)

sshow
sshow

Reputation: 9104

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

Upvotes: 6

Related Questions