zoukankan      html  css  js  c++  java
  • webform下拉列表、列表框

    下拉列表:DropDownList
    1.绑定数据:
    DropDownList1.DataSource = context.Nation;
    DropDownList1.DataValueField = "Code";
    DropDownList1.DataTextField = "Name";

    DropDownList1.DataBind();

    2.取选中项的值
    DropDownList1.SelectedValue.ToString();

    3.设置哪一项选中
    DropDownList1.SelectedIndex = 2; //方式1
    foreach (ListItem item in DropDownList1.Items)//方式二
    {
    if (item.Value == "n002")
    {
    item.Selected = true;
    }
    }

    ListBox:列表框
    1.绑定数据:
    ListBox1.DataSource = context.Nation;
    ListBox1.DataTextField = "Name";
    ListBox1.DataValueField = "Code";

    ListBox1.DataBind();
    2.取选中项的值:
    单选:ListBox1.SelectedValue.ToString();
    多选:
    foreach (ListItem item in ListBox1.Items)
    {
    if (item.Selected)
    {
    Label1.Text += item.Value;
    }
    }
    3.设置哪项被选中
    foreach (ListItem item in ListBox1.Items)
    {
    if (item.Text=="汉族" || item.Text=="满族")
    {
    item.Selected = true;
    }
    }

  • 相关阅读:
    spring声明式事务管理详情解析
    Nginx nginx.conf配置文件详细说明
    etcd
    rsyslog使用简介
    LINUX常见命令
    kafka简介&使用
    kafka安装
    Zookeeper简介&应用场景
    Zookeeper安装
    安装JDK
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/5051976.html
Copyright © 2011-2022 走看看