日期:2014-05-17  浏览次数:20553 次

谁帮解释下如下代码
C# code
protected void repFirmList_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            if((e.Item.ItemType == ListItemType.Item )|| (e.Item.ItemType==ListItemType.AlternatingItem))
            {
                Label lb = (Label)e.Item.FindControl("Label15");
                lb.Text = "0";
                foreach (DataRow dr in NoReplyCount.Rows)
                {
                    if (dr["TradeInfoId"].ToString() == DataBinder.Eval(e.Item.DataItem, "Id").ToString())
                    {
                        lb.Text = dr["count"].ToString();
                        break;
                    }
                }
            }
        }


------解决方案--------------------
C# code

//List Bound事件
protected void repFirmList_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            //如果为类型为普通项或者交替项
            if((e.Item.ItemType == ListItemType.Item )|| (e.Item.ItemType==ListItemType.AlternatingItem))
            {
                //找到当前项ID为Lable5的Label
                Label lb = (Label)e.Item.FindControl("Label15");
                lb.Text = "0";

                //遍历所有行
                foreach (DataRow dr in NoReplyCount.Rows)
                {
                    //如果该行的TradeInfoId 和 当前行绑定的ID相等
                    if (dr["TradeInfoId"].ToString() == DataBinder.Eval(e.Item.DataItem, "Id").ToString())
                    {
                        //更改Lable的值
                        lb.Text = dr["count"].ToString();
                        break;
                    }
                }
            }
        }