更改 ListView 在 itemCreated 事件中创建的行的样式
当渲染数据绑定 ListView 时,我想根据结果动态设置每行的背景颜色,在我的例子中为红色、橙色和绿色。
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
DataRow myRow;
DataRowView myRowView;
myRowView = (DataRowView)e.Item.DataItem;
myRow = myRowView.Row;
if (myRow[2].ToString().CompareTo("") == 1)
{
// Colour coding here..
}
}
是否可以到达每一行的TR标签来更改样式?
非常感谢, 斯特凡
When render a databound ListView I want to dynamically set the background colour of each row depending on the results, in my case Red, Orange and Green.
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
DataRow myRow;
DataRowView myRowView;
myRowView = (DataRowView)e.Item.DataItem;
myRow = myRowView.Row;
if (myRow[2].ToString().CompareTo("") == 1)
{
// Colour coding here..
}
}
Is it possible to reach the TR tag for each row to change the style?
Many thanks,
Stefan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TR 标签必须具有 runat="server" 才能使用服务器端代码;但是,您可以通过检查该项目的子项控件来注入它,而无需这样做; HTML 中可能有一个 Literal 或 LiteralControl,您可以使用字符串操作来注入...
The TR tag would have to have runat="server" to use server-side code; however, you may be able to inject it in without that by examining the controls that are the child of the item; there's probably a Literal or LiteralControl with the HTML, and you can use string manipulation to inject...
在布莱恩的大力帮助下,我找到了解决问题的方法。
我有一个 ListView,我添加了一个 id 标签(trRow)和标签 runat="server",如下所示:
在它后面的代码中看起来像这样:
其中的一些逻辑仍然不正确等,只是为了展示我如何解决这个问题问题是动态更改每行的背景颜色。
I worked out a solution to my problem, with some good help from Brian.
I have a ListView and I added an id tag (trRow) and tag runat="server" like this:
In code behind it looks like this:
Some of the logic in there is still not correct etc, just to show how I solved the issue to dynamically change the background color of each row.