问题
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