datalist itemdatabound 事件在根据条件更改项目背景颜色时出现问题
嘿伙计们,我正在尝试做一些非常简单的事情..我正在检查数据行中的数据列是否> > 0 我希望数据列表中的项目背景颜色为绿色,如果它< 0 保持透明...
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)(e.Item.DataItem);
int rating = int.Parse(drv.Row["rating"].ToString());
if (rating > 0)
{
e.Item.BackColor = System.Drawing.Color.Green;
}
}
我已经使用调试器进行了调试,它满足了所有条件,颜色没有改变。我知道它必须是简单的东西,我只是看不到它。
Hey guys I'm trying to do something really simple.. I'm checking a data column in my datarow if it's > 0 I want the item back color in the datalist to be green if its < 0 remain transparent...
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)(e.Item.DataItem);
int rating = int.Parse(drv.Row["rating"].ToString());
if (rating > 0)
{
e.Item.BackColor = System.Drawing.Color.Green;
}
}
I've stepped through with debugger and it's hitting all the conditions the color just isn't changing.. I know it has to be something simple I just can't see it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用 e.Item.FindControl 实例化要更改其背景颜色的控件的实例。
You need to use the e.Item.FindControl to instantiate an instance of the control you want to change the background color of.
这段代码放在哪里?它需要位于
OnRowDataBound()
事件上。看起来您可能会将以上内容放入OnItemDataBound()
中。Where are the putting this code? It needs to be on the
OnRowDataBound()
event. It looks like you might be putting the above inOnItemDataBound()
.