Shankha Subhra Ghosh
Shankha Subhra Ghosh

Reputation: 21

How to set repeater control back colour by item index?

I am using a DataRepeater control to show a popup. I am able to set BackColor of the current item by this code

private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
{
   dataRepeater1.CurrentItem.BackColor = Color.Red;
}

but I am unable to add BackColor white for the previous item. Also I want to change the BackColor of the item form the list I am hovering mouse.

Upvotes: 0

Views: 184

Answers (1)

Dialecticus
Dialecticus

Reputation: 16761

One way to solve this is to have one more property in your class, maybe called DataRepeater1_PreviousItem:

class YourClass
{
    DataRepeaterItem DataRepeater1_PreviousItem { get; set; }

    // ... some other code

    private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
    {
        if (DataRepeater1_PreviousItem != null)
            DataRepeater1_PreviousItem.BackColor = Color.White;

        dataRepeater1.CurrentItem.BackColor = Color.Red;

        DataRepeater1_PreviousItem = dataRepeater1.CurrentItem;
    }
}

Upvotes: 0

Related Questions