Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i write this code for setting backcolor of datalist items
C#
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;  
}


But on dlTrades_itemCommand event backcolor of items goes away... how can i keep these color on itemcommand event???
Reply ASAP
Posted
Updated 19-Sep-11 20:05pm
v3

put the breake point on itemdatabound event and then try to fire itemcommand event check after completion of your dlTrades_itemCommand event your code again goes to dlTrades_ItemDataBound this or not..

if it is not going to there then for getting a back color you have to refreace your list after your dlTrades_itemCommand event is complete


try this it will i think after you debug your code you will find that where is your code is weak to rebind the back color..
 
Share this answer
 
Refer this link,

http://msdn.microsoft.com/en-us/library/6y92e1ze.aspx[^]

U need to bind your datalist after itemCommand.
 
Share this answer
 
Hi,

Try this-

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("table tr:odd").css("background-color", "red");
        $("table tr:even").css("background-color", "gray");
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:DataList ID="DataList1" runat="server" RepeatColumns="1" RepeatDirection="Vertical">
        <ItemTemplate>
            <div>
                <img src='<%#Eval("Url")%>' /><br />
                <span><%#Eval("Caption")%></span>
            </div>
        </ItemTemplate>
    </asp:DataList>
    </form>
</body>
</html>
 
Share this answer
 

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