[英]Link button inside a Repeater control, how to change the background/foreground color of clicked item?
我想显示一周中的某天的列表(动态的,一整天的时间,有时只有2-3天),然后用户将单击“天”并刷新同一页面。 以上功能是通过以下代码实现的。
<asp:Repeater ID="DayList" Runat="server">
<ItemTemplate>
<asp:LinkButton ID="lbDayList" Runat="server" CommandName='<%# DataBinder.Eval (Container.DataItem, "wkdayVal")%>'
OnCommand="lbDayList_click"
DataBinder.Eval(Container.DataItem, "wkday")%>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
我想用不同的颜色显示点击的日子! 请帮助实现此功能!
您是否考虑过创建styles.css页面并使用LinkButton的CssClass=""
属性?
在您的styles.css文件中,您将具有以下内容:
.Visited
{
color: #fff;
background: inherit;
text-decoration: none;
}
然后您的链接按钮的css属性将使用类似
CssClass="visited"
您将需要在Repeater的PreRender部分上执行此操作,因此将Repeater的OnPreRender
属性设置为Repeater_OnPreRender
。 然后在您的代码隐藏中创建一个像这样的函数
protected void Repeater_OnPreRender(object sender, EventArgs e)
{
//get the index of the selected item
//loop through your items colleciton until you find the item with the corresponding index
//find your link button
//set your link button's css attribute.
}
之所以要在PreRender
阶段执行此操作,是因为转发器已经加载了数据,并且尚未创建传递回Web浏览器的HTML。
希望这可以帮助。 GS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.