简体   繁体   English

ItemCommand中的中继器突出显示项目

[英]Repeater Highlight Item in ItemCommand

I have a repeater, which inside I bind some usercontrol with Panel. 我有一个中继器,在其中我将一些用户控件与Panel绑定在一起。 The panel has a OnClick event and raise a ItemCommand . 该面板具有一个OnClick事件,并引发一个ItemCommand I am aware that the DataItem is not persist throughout the postback and therefore it will be null during the ItemCommand event, my requirement is to change the color of the particular usercontrol when it is clicked (without using Javascript). 我知道DataItem在整个回发过程中不会持久存在,因此在ItemCommand事件期间它将为null,我的要求是在单击特定的usercontrol时更改其颜色(不使用Javascript)。 Anyone has an idea? 有人有主意吗?

You can try altering class names of the particular usercontrols onClick in itemDataBound event like below 您可以尝试更改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));
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM