如何设置数据列表行的颜色 [英] how to set color of datalist rows

查看:377
本文介绍了如何设置数据列表行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为qu的表(id,名称,颜色).我想用此表在前端填充数据列表,并且相应ID的行颜色应该b数据库表中的颜色名称.我该怎么办...

像:
如果记录是这些
1,公羊,红色
2,莫汉,蓝色

然后

ram所在的数据列表行的颜色应为红色,因此对于mohan为蓝色

更新::
Pawar给出的解决方案在页面加载的第一时间效果很好.
但是在回发时,回发itemdatabound上的所有颜色都会变暗bcoz.
所以我该如何在itemcommand事件上保留颜色...
帮助我

i have a table named qu (id, name, color). i want to fill datalist on front end with this table and the row color of corresponding id shoud b the color name in database table. how can i do this...

like:
if records are these
1, ram, red
2, mohan , blue

then

color of datalist row in which ram resides should b red and so for mohan is blue

Updates::
solution as given by Pawar worked fine firstime the page loads
but on postback all colors are dimnished bcoz on postback itemdatabound doesnt fire.
so how can i keep colors on itemcommand event...
help me

推荐答案




尝试使用此行基于数据库设置项目的颜色

Hi,


Try this line for setting color of item based on database

<itemstyle backcolor="<%#Eval("color") %>" />



希望对您有所帮助.


一切顺利.



I hope it can help you.


All the best.


protected void dlTrades_ItemDataBound(object sender, DataListItemEventArgs e) {     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)     
{
System.Data.DataRowView drv = (System.Data.DataRowView)(e.Item.DataItem);          
string hld = (string)drv.Row["Color"].ToString();         
 if (hld == "RED")         
{             
e.Item.BackColor = System.Drawing.Color.Red;  
}//same way do it for other          
} 


这篇关于如何设置数据列表行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆