I want to get the last record detail from repeater control. can开发者_高级运维 someone help?
more detail : in my database there is number of days inserted. the last record shows the total days of tours. so i want that last record value from repea
In code behind you can use the ItemDataBound
event to get the details of the last item:
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.ItemIndex == rpt.Items.Count - 1)
{
// this repeater item refers to the last record
}
}
}
protected void rptUserStat_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//reference the repeater item.
RepeaterItem item = e.Item;
//reference the controls.
Label lbltotal = (item.FindControl("lblgoldname") as Label);
Label lblamount = (item.FindControl("lblgoldDonationAmount") as Label);
if (lbltotal.Text.ToUpper() == "TOTAL")
{
int footerindex = e.Item.ItemIndex;
HtmlTableRow htmlrow = (HtmlTableRow)e.Item.FindControl("trgold");
htmlrow.BgColor = "#DDCECB";
lbltotal.Style.Add("Font-Weight", "bold");
lbltotal.Style.Add("color", "cadetblue");
lblamount.Style.Add("Font-Weight", "bold");
lblamount.Style.Add("color", "cadetblue");
}
}
}
精彩评论