C# ItemDataBound与中继器如何处理 protectedvoid rptLastPromotion\u ItemDataBound(对象发送方,System.Web.UI.WebControls.RepeaterItemEventArgs e) { HtmlAnchor aView=(HtmlAnchor)e.Item.FindControl(“描述”); Label lbldescriptionlink=(Label)e.Item.FindControl(“lblDescription”); Label lbldescriptionNoLink=(Label)e.Item.FindControl(“lblDescription2”); HiddenField hfIsNewTab=(HiddenField)e.Item.FindControl(“hfNewTab”); 对于(int i=0;i
您的问题非常模糊,但我相信您的问题可能是您没有检查repeater item Type。执行此操作的标准方法是:C# ItemDataBound与中继器如何处理 protectedvoid rptLastPromotion\u ItemDataBound(对象发送方,System.Web.UI.WebControls.RepeaterItemEventArgs e) { HtmlAnchor aView=(HtmlAnchor)e.Item.FindControl(“描述”); Label lbldescriptionlink=(Label)e.Item.FindControl(“lblDescription”); Label lbldescriptionNoLink=(Label)e.Item.FindControl(“lblDescription2”); HiddenField hfIsNewTab=(HiddenField)e.Item.FindControl(“hfNewTab”); 对于(int i=0;i,c#,repeater,C#,Repeater,您的问题非常模糊,但我相信您的问题可能是您没有检查repeater item Type。执行此操作的标准方法是: protected void rptLastPromotion_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { HtmlAnchor aView = (HtmlAnchor)e.Item.FindControl("a
protected void rptLastPromotion_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
HtmlAnchor aView = (HtmlAnchor)e.Item.FindControl("aDescription");
Label lbldescriptionlink = (Label)e.Item.FindControl("lblDescription");
Label lbldescriptionNoLink = (Label)e.Item.FindControl("lblDescription2");
HiddenField hfIsNewTab = (HiddenField)e.Item.FindControl("hfNewTab");
for (int i = 0; i <= rptLastPromotion.Items.Count; i++)
{
if (!String.IsNullOrEmpty(aView.HRef))
{
lbldescriptionlink.Visible = true;
lbldescriptionNoLink.Visible = false;
if (Convert.ToBoolean(hfIsNewTab.Value) == true)
{
aView.Target = "_blank";
}
}
else
{
lbldescriptionlink.Visible = false;
lbldescriptionNoLink.Visible = true;
}
}
}
此外,不需要在中继器的项目上循环。(
对于(int i=0;i您需要检查中继器的ItemType
内部ItemDataBound
事件
protected void rptLastPromotion_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
HtmlAnchor aView = (HtmlAnchor)e.Item.FindControl("aDescription");
Label lbldescriptionlink = (Label)e.Item.FindControl("lblDescription");
Label lbldescriptionNoLink = (Label)e.Item.FindControl("lblDescription2");
HiddenField hfIsNewTab = (HiddenField)e.Item.FindControl("hfNewTab");
if (!String.IsNullOrEmpty(aView.HRef))
{
lbldescriptionlink.Visible = true;
lbldescriptionNoLink.Visible = false;
if (Convert.ToBoolean(hfIsNewTab.Value) == true)
{
aView.Target = "_blank";
}
}
else
{
lbldescriptionlink.Visible = false;
lbldescriptionNoLink.Visible = true;
}
}
}
这个答案有用吗?你有什么问题吗?
protected void rptLastPromotion_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
HtmlAnchor aView = (HtmlAnchor)e.Item.FindControl("aDescription");
Label lbldescriptionlink = (Label)e.Item.FindControl("lblDescription");
Label lbldescriptionNoLink = (Label)e.Item.FindControl("lblDescription2");
HiddenField hfIsNewTab = (HiddenField)e.Item.FindControl("hfNewTab");
if (!String.IsNullOrEmpty(aView.HRef))
{
lbldescriptionlink.Visible = true;
lbldescriptionNoLink.Visible = false;
if (Convert.ToBoolean(hfIsNewTab.Value) == true)
{
aView.Target = "_blank";
}
}
else
{
lbldescriptionlink.Visible = false;
lbldescriptionNoLink.Visible = true;
}
}
}
protected void rptLastPromotion_ItemDataBound(object sender,System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// write your logic here
}
}