将滚动条添加到RadioButtonList

时间:2013-11-21 09:04:46

标签: c# asp.net

我有这个包含很多项的RadioButtonList,所以我需要添加一个垂直滚动条。这是我向RadioButtonList添加项目的代码

    var Meals = Factory.Meals.List();
    var MealVotes = Factory.MealVotes.List(item => item.VoteDate == DateTime.Today);
    var MealVote = Factory.MealVotes.List(item => item.VoteDate == DateTime.Today && item.UserId == Instance.CurrentUserId).ToList().FirstOrDefault();

        foreach (var meal in Meals)
        {
            mealVotes = 0;
            TotalVotes = 0;

            foreach (var mealVote in MealVotes)
            {
                if (meal.Id == mealVote.MealId)
                {
                    mealVotes++;
                }

                TotalVotes++;
            }

            if (TotalVotes > 0)
            {
                Width = (100M / TotalVotes) * mealVotes;
            };

            VoteMealRadioButtonList.Items.Add(
                new ListItem(
                    meal.Title + " " + mealVotes +
                    @"<div style=""height: 10px; width:130px;"">" +
                        @"<a style=""float: left; width: 30px""></a>" +
                        @"<div style=""float: left; height: 10px; width:" + Width + @"px; background: DarkCyan;""></div>" +
                    "</div>",
                    meal.Id.ToString()
                )
            );
        }

        VoteMealRadioButtonList.SelectedValue = MealVote.MealId.ToString();

看起来像这样:

enter image description here

不要担心名单和膳食名称(使用我的母语)。如果列表中会有这么多的饭菜,那就不会有问题,但会有50顿饭或类似的东西,所以这就是我想添加一个垂直滚动条的原因。

无论如何我可以添加滚动条吗?

1 个答案:

答案 0 :(得分:1)

为什么不将radiobuttonlist放入div并将滚动条添加到此div?