0
votes

I have a repeater, which inside I bind some usercontrol with Panel. The panel has a OnClick event and raise a 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). Anyone has an idea?

1
"without using Javascript" why do you wanat to avoid JS. - sajanyamaha
RepeaterCommandEventArgs e.Item won't be null in the ItemCommand event of the repeater if you have EnableViewState="true". - Devraj Gadhavi
@sajanyamaha it's the requirement - drhanlau
@DevrajGadhavi EnableViewState is always true and once you post back the repeater will not retain any DataItem, I am talking about DataItem not just e.Item - drhanlau
But you can find any control placed in repeater, via e.Item.FindControl("controlid"). Can't you? Also you get three parameters e.CommandName, e.CommandArgument, e.CommandSource. Pardon me if I am misunderstanding your question or requirement. - Devraj Gadhavi

1 Answers

0
votes

You can try altering class names of the particular usercontrols onClick in itemDataBound event like below

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));
     }
}