用数字填充asp.net下拉列表 [英] Populate asp.net dropdownlist with number

查看:91
本文介绍了用数字填充asp.net下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的查询,我想填充从17到90的数字下拉列表,最后一个数字应该是一个像90+而不是90的字符串。我猜这个逻辑会使用一个for循环: / p>

A simple query , i want to populate the dropdownlist with number starting from 17 to 90 , and the last number should be a string like 90+ instead of 90. I guess the logic will be using a for loop something like:

for (int a = 17; a <= 90; a++)
        {
            ddlAge.Items.Add(a.ToString());
        }

此外,我想填充相同的每个列表项的文本和值数字。
任何想法?

Also I want to populate the text and value of each list item with the same numbers. Any ideas?

推荐答案

for (int i = 17; i < 90; i++)
{
    ddlAge.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
ddlAge.Items.Add(new ListItem("90+", "90"));

这篇关于用数字填充asp.net下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆