Change Color Datalist

I have aprox 18 data list controls in my page and I amtrying to change each cell color accordin to the status in the database for which i am using the following code,  the problem is that it changes the color on one datalist eg datalist1 and the other datalists turn all back to white cells, I want to handle this event and keep the other datalist as well , can someone help me??
// Different Color Codes For Possible//

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item ||
          e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = (DataRowView)(e.Item.DataItem);

            string status = drv.Row["Status"].ToString();
            if (status == "Available")
                e.Item.BackColor = System.Drawing.Color.LightGreen;
            if (status == "Assigned")
                e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
            if (status == "BR")
                e.Item.BackColor = System.Drawing.Color.LightSalmon;

        }


    }//End Nt1 Change Colors


    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item ||
          e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = (DataRowView)(e.Item.DataItem);

            string status = drv.Row["Status"].ToString();
            if (status == "Available")
                e.Item.BackColor = System.Drawing.Color.LightGreen;
            if (status == "Assigned")
                e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
            if (status == "BR")
                e.Item.BackColor = System.Drawing.Color.LightSalmon;
        }


    }


..
...

Open in new window

LVL 9
TonyRebaAsked:
Who is Participating?
 
RickConnect With a Mentor Commented:
You are changing colors using the  ItemDataBound event.
You need to call DataList(N)_ItemDataBound for all Data Lists every time you bind data do any Data List.
Does that make sense?
0
 
IgorNedCommented:
TonyReba, I have a similar code in my project, and it works correctly, it doesn’t change the color of other DataLists back to white when I change the color of the first DataList in DataList1_ItemDataBound handler. Check your other code.
0
 
TonyRebaAuthor Commented:
So what  could be the issue, I have a feeling is with the databound events, that might be called incorrectly...

can you please give it a look to my code and see if we you can find the iisue?
0
 
IgorNedCommented:
I don't see any problem with the code you posted.
May be it is in aspx script?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.