现在的位置: 首页 > 综合 > 正文

DropDownList–下拉菜单

2012年06月17日 ⁄ 综合 ⁄ 共 759字 ⁄ 字号 评论关闭
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(
1new ListItem("222""222"));//插入到第2个位置

抱歉!评论已关闭.