• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我的学习笔记
   首页       联系   管理    订阅  订阅

DropDownList--下拉菜单

1、ArrayList数据列表(使用数据列表必须引入using System.Collections命名空间)
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            ArrayList arrl 
= new ArrayList();
            arrl.Add(
"李明");
            arrl.Add(
"王云");
            arrl.Add(
"乐乐");
            DropDownList1.DataSource
= arrl; //将数据列表作为DropDownList1的数据源
            DropDownList1.DataBind();
        }

    }

2、多态添加下拉列表项

 protected void Button1_Click(object sender, EventArgs e)
    
{
        DropDownList4.Items.Add(TextBox1.Text.ToString());
    }

3、分别添加Text,Value值,与插入项
            DropDownList4.Items.Add(new ListItem("111", "111"));
            DropDownList4.Items.Add(
new ListItem("122", "122"));   
            DropDownList4.Items.Insert(
1, new ListItem("222", "222"));//插入到第2个位置

posted @ 2007-12-20 20:52  吴有鋆  阅读(204)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3