zoukankan      html  css  js  c++  java
  • DropDownList控件的使用方法

    1. 使用代码添加数据

            <asp:DropDownList ID="DropDownList1" runat="server">
            </asp:DropDownList>
           
    //1.1使用代码添加数据
            ListItem item = new ListItem(".net","1");
            this.DropDownList1.Items.Add(item);
            item = new ListItem("java", "2");
            this.DropDownList1.Items.Add(item);
            item = new ListItem("php", "3");
            this.DropDownList1.Items.Add(item);
            item = new ListItem("选择全部", "0");
            this.DropDownList1.Items.Insert(0, item);//在第一个索引处添加‘选择全部’选项

    2. 使用代码绑定数据源

            <asp:DropDownList ID="DropDownList2" runat="server">
            </asp:DropDownList>
     
    //2.1使用代码绑定数据源
            CategoriesManager manager = new CategoriesManager();
            this.DropDownList2.DataSource=manager.GetDataTable();
            this.DropDownList2.DataTextField = "name";
            this.DropDownList2.DataValueField = "id";
            this.DropDownList2.DataBind();
            this.DropDownList2.Items.Insert(0,new ListItem("选择全部", "0"));

    3. 使用数据绑定控件绑定数据源

            <asp:DropDownList ID="DropDownList3" runat="server" 
                DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:BookShopConnectionString %>" 
                SelectCommand="SELECT [Id], [Name] FROM [Categories]"></asp:SqlDataSource>
  • 相关阅读:
    5 Python3 函数进阶&迭代器与生成器
    2 python第三章文件操作
    4 python内置函数
    python内置函数 eval()、exec()以及complie()函数
    0 字符与字节的区别
    python enumerate() 函数
    1 python 文件处理
    python 之编写登陆接口
    python 之九九乘法表
    第一模块第二章-数据类型整理
  • 原文地址:https://www.cnblogs.com/xyyt/p/3979097.html
Copyright © 2011-2022 走看看