[英]Repeater Highlight Item in ItemCommand
我有一個中繼器,在其中我將一些用戶控件與Panel綁定在一起。 該面板具有一個OnClick
事件,並引發一個ItemCommand
。 我知道DataItem
在整個回發過程中不會持久存在,因此在ItemCommand
事件期間它將為null,我的要求是在單擊特定的usercontrol時更改其顏色(不使用Javascript)。 有人有主意嗎?
您可以嘗試更改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.