简体   繁体   English

如何通过项目索引设置中继器控件的背景色?

[英]How to set repeater control back colour by item index?

I am using a DataRepeater control to show a popup. 我正在使用DataRepeater控件显示弹出窗口。 I am able to set BackColor of the current item by this code 我可以通过此代码设置当前项目的BackColor

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. 但是我无法为上一项添加BackColor white。 Also I want to change the BackColor of the item form the list I am hovering mouse. 我也想从鼠标悬停的列表中更改项目的BackColor

One way to solve this is to have one more property in your class, maybe called DataRepeater1_PreviousItem : 解决此问题的一种方法是在您的类中再增加一个属性,也许称为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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM