如何从转发器控制中获得最后的记录值。

时间:2011-09-10 12:30:18

标签: c# asp.net repeater

我想从转发器控件中获取最后一条记录详细信息。有人可以帮忙吗?

更多细节: 在我的数据库中插入了天数。最后一条记录显示了游览的总天数。所以我想要来自repea的最后一个记录值

2 个答案:

答案 0 :(得分:7)

在后面的代码中,您可以使用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
        }            
    }
}

答案 1 :(得分:0)

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