0

我在我的应用程序中使用 radrotator,如何从 asp.net c# 代码后面更改旋转器所选项目的边框颜色或颜色,我可以期待一些帮助吗?

4

1 回答 1

2

您可以通过其他 CSS 类更改 RadRotator 控件及其项目的边框:

  1. 可以覆盖内部 CSS 类rrClipRegion以便为旋转器控件的边框设置新颜色:

    .rrClipRegion
    {
        border: 1px solid green !important;
    }
    
  2. 您可以通过 CSS 为 RadRotator 的项目设置默认边框颜色,然后您可以通过定义具有新边框颜色的 CSS 类从后面的代码中更改它,如下所示:

RadRotator 标记:

    <telerik:RadRotator ID="RadRotator1" runat="server" FrameDuration="3000" ScrollDirection="Left"
        Height="123px" ItemHeight="113px" Width="180px" ItemWidth="152px" Skin="Default"
        RotatorType="Buttons" OnItemClick="RadRotator1_ItemClick">
        <ItemTemplate>
            <div>
                <img src="....." alt="" />
            </div>
        </ItemTemplate>
    </telerik:RadRotator>

应用边框所需的样式:

<style type="text/css">
    .rrItem
    {
        margin: 4px;
    }

    .rrItem img
    {
        border: 1px solid grey;
    }

    .cssSelectedItem img
    {
        border: 1px solid red;

    }
</style>

从代码隐藏更改项目的边框颜色:

protected void RadRotator1_ItemClick(object sender, RadRotatorEventArgs e)
{
    RadRotatorItem item = (RadRotatorItem)e.Item;
    item.CssClass = "cssSelectedItem";

    RadRotator1.InitialItemIndex = e.Item.Index;
}

请注意,我设置了旋转器控件的InitialItemIndex属性,以便通过回发保留当前项目。此外,该示例是为尺寸为 150x113 的图像设计的,因此如果使用不同的尺寸,您应该相应地更改属性WidthHeightItemWidthItemHeight

于 2011-10-31T13:29:38.300 回答