Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 中继器跳过ItemDataBound上的第一行_C#_Asp.net - Fatal编程技术网

C# 中继器跳过ItemDataBound上的第一行

C# 中继器跳过ItemDataBound上的第一行,c#,asp.net,C#,Asp.net,我有一个带有9项的中继器,其中的值在客户端页面上分配,所有9项都显示完整 我正在使用ItemDataBound在服务器端编辑项目图像,但它只返回9个中的8个。我对它进行了调试,但它从未拾取第一项。有什么想法吗 ASPX: 正如@Lincolnk所提到的,删除下面的行修复了这个问题。即使在使用ri.findcontrol引用要查找的控件时,也存在此问题。通过删除并使用e.Item.FindControl进行修复 protected void rep_FeaturedProds_OnItemData

我有一个带有9项的中继器,其中的值在客户端页面上分配,所有9项都显示完整

我正在使用ItemDataBound在服务器端编辑项目图像,但它只返回9个中的8个。我对它进行了调试,但它从未拾取第一项。有什么想法吗

ASPX:


正如@Lincolnk所提到的,删除下面的行修复了这个问题。即使在使用ri.findcontrol引用要查找的控件时,也存在此问题。通过删除并使用e.Item.FindControl进行修复

protected void rep_FeaturedProds_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        foreach (RepeaterItem ri in rep_FeaturedProds.Items)
        {
            HtmlImage imgProduct_Thumb = (HtmlImage)e.Item.FindControl("imgProduct_Thumb");
            HiddenField hfImageFileName = (HiddenField)e.Item.FindControl("hfDecId");
            HtmlGenericControl Homepage_FeaturedProds_BG = (HtmlGenericControl)e.Item.FindControl("Homepage_FeaturedProds_BG");

            string imgPath = "~/Uploads/Images/ProductThumbs/";
            string decId = hfImageFileName.Value + "_thumb.png";

            if (System.IO.File.Exists(Server.MapPath(imgPath + decId)))
            {
                imgProduct_Thumb.Src = imgPath + decId;
            }
            else
            {
                imgProduct_Thumb.Src = imgPath + "0000_thumb.png";

            }
        }
    }
}

您是否尝试过调试代码以查看事件代码中是否存在任何问题?您的
foreach
循环没有完成任何操作,您可以删除该行。@lincolnk-这就是问题所在。我将它作为ri.FindControl用于FindControl,并将其更改为e.item。不管怎样都是这样。我已经编辑了你的标题。请参阅“”,其中一致意见是“不,他们不应该”。将.Items切换到.Controls可修复此问题。不需要移除foreach。
protected void rep_FeaturedProds_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        foreach (RepeaterItem ri in rep_FeaturedProds.Items)
        {
            HtmlImage imgProduct_Thumb = (HtmlImage)e.Item.FindControl("imgProduct_Thumb");
            HiddenField hfImageFileName = (HiddenField)e.Item.FindControl("hfDecId");
            HtmlGenericControl Homepage_FeaturedProds_BG = (HtmlGenericControl)e.Item.FindControl("Homepage_FeaturedProds_BG");

            string imgPath = "~/Uploads/Images/ProductThumbs/";
            string decId = hfImageFileName.Value + "_thumb.png";

            if (System.IO.File.Exists(Server.MapPath(imgPath + decId)))
            {
                imgProduct_Thumb.Src = imgPath + decId;
            }
            else
            {
                imgProduct_Thumb.Src = imgPath + "0000_thumb.png";

            }
        }
    }
}
foreach (RepeaterItem ri in rep_FeaturedProds.Items)