【问题标题】:Repeater Highlight Item in ItemCommandItemCommand 中的Repeater 突出显示项
【发布时间】:2012-11-27 13:02:10
【问题描述】:

我有一个中继器,在其中我将一些用户控件与 Panel 绑定。该面板有一个OnClick 事件并引发ItemCommand。我知道DataItem 不会在整个回发过程中持续存在,因此在ItemCommand 事件期间它将为空,我的要求是在单击特定用户控件时更改它的颜色(不使用Javascript)。有人有想法吗?

【问题讨论】:

  • “不使用Javascript”你为什么要避免JS。
  • RepeaterCommandEventArgs 如果您有 EnableViewState="true",则 e.Item 在中继器的 ItemCommand 事件中不会为空。
  • @sajanyamaha 这是要求
  • @DevrajGadhavi EnableViewState 始终为真,一旦你发回转发器将不会保留任何 DataItem,我说的是 DataItem 而不仅仅是 e.Item
  • 但是您可以通过 e.Item.FindControl("controlid") 找到放置在转发器中的任何控件。你不能吗?您还可以得到三个参数 e.CommandNamee.CommandArgumente.CommandSource。如果我误解了您的问题或要求,请原谅我。

标签: c# .net repeater


【解决方案1】:

您可以尝试在 itemDataBound 事件中更改特定用户控件 onClick 的类名,如下所示

protected void DataList1_ItemDataBound(object sender, 
                             DataListItemEventArgs e) 
{
     if (e.Item.ItemType == ListItemType.Item || 
         e.Item.ItemType == ListItemType.AlternatingItem)
     { 
         //Add eventhandlers for highlighting 
         //a DataListItem when the mouse hovers over it.
         e.Item.Attributes.Add("onmouseover", 
                "this.oldClass = this.className;" + 
                " this.className = 'EntryLineHover'"); 
         e.Item.Attributes.Add("onmouseout", 
                "this.className = this.oldClass;");
         //Add eventhandler for simulating 
         //a click on the 'SelectButton'
         e.Item.Attributes.Add("onclick", 
                this.Page.ClientScript.GetPostBackEventReference(
                e.Item.Controls[1], string.Empty));
     }
}

【讨论】:

  • 但是如果当用户点击另一个项目时,我需要清除之前突出显示的项目怎么办?这就是我想在 itemCommand 中这样做的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-16
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多