Listview等数据容器的奇偶行样式设置

前台tr样式设置 

<tr class='<%# GetCssName(Container) %>'>

Container为数据源的容器,是一个属性

 

    /// <summary>
    /// listview隔行不同样式
    /// </summary>
    /// <param name="container"></param>
    /// <returns>CssName</returns>
    public string GetCssName(object container)
    {
        if (container != null)
        {
            if (container.GetType() == typeof(ListViewDataItem))
            {
                if ((((ListViewDataItem)container).DisplayIndex % 2) == 0)
                {
                    return "col1";
                }
                else
                {
                    return "col2";
                }
            }
        }
        return null;
    }

posted on 2012-01-11 10:09  风华之恋  阅读(399)  评论(0编辑  收藏  举报