Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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
Posted
Updated 19-Sep-11 5:37am
v2

Hi,


Try this line for setting color of item based on database

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


I hope it can help you.


All the best.
 
Share this answer
 
Comments
choudhary.sumit 19-Sep-11 10:15am    
i got this error please resolve...
Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.TableItemStyle does not have a DataBinding event.
Muralikrishna8811 19-Sep-11 10:17am    
try this line your are using table for item right.

<tr bgcolor ='<%#Eval("color") %>'>

by using this you can set bgcolor for entire row
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          
} 
 
Share this answer
 
Comments
choudhary.sumit 19-Sep-11 10:23am    
Thanx pawar.. Problem Resolved.!!
Anuja Pawar Indore 20-Sep-11 2:00am    
WC :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900