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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RickCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.