我怎样才能从转发器控制得到最后的记录值

本文关键字:最后的 记录 控制 转发器 | 更新日期: 2023-09-27 18:08:05

我想从中继器控件获得最后的记录细节。有人能帮忙吗?

更多细节:在我的数据库中有插入的天数。最后一个记录显示了旅行的总天数。我想要的是repea

我怎样才能从转发器控制得到最后的记录值

中的最后一个记录值

在后面的代码中,您可以使用ItemDataBound事件来获取最后一项的详细信息:

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