zoukankan      html  css  js  c++  java
  • C#_控件——DropDownList

    1.html

                <asp:CheckBox ID="CheckBox11" runat="server" onclick="changechecked(this)" />车身颜色:
                <asp:DropDownList ID="DropDownList5" runat="server">
                    <asp:ListItem Text="红色" Value="红色的" Enabled="true" Selected="True"></asp:ListItem>
                    <asp:ListItem Text="绿色" Value="绿色的" />
                </asp:DropDownList>

    2.code

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    //Text一般用来前台显示给用户看的
                    //Value一般用于表单提交,提交给后台的数据
                    string l5_text = DropDownList5.SelectedItem.Text;//红色
                    string l5_value = DropDownList5.SelectedItem.Value;//红色的
                    string l5_value1 = DropDownList5.SelectedValue.ToString();//红色的      
                    string text1 = DropDownList5.Items[1].Text;//绿色
                    string value1 = DropDownList5.Items[1].Value;//绿色的
                    bool IsSelected = DropDownList5.Items[1].Selected; //绿色的
                    //t添加动态数据给下拉列表
                    DataSet ds = new DataSet();//此处只是举例,DataSet一定要实例化的
                    DropDownList5.DataSource = ds.Tables["dmsm1"].DefaultView;//"dmsm1"为数据库的名称
                    DropDownList5.DataTextField = "dmz";//dmz为数据库的字段名称
                    DropDownList5.DataValueField = "dmz";  
                    DropDownList5.DataBind();
                    //添加静态数据给下拉列表
                    DropDownList5.Items.Insert(0,"----请选择----");
                    DropDownList5.Items[1].Selected = false;
                    DropDownList5.Items[0].Selected = true ;
                    //DropDownList5.Items[1].Selected = true;
                }
                bool check2 = CheckBox2.Checked;
            }

     3.

     

  • 相关阅读:
    2017"百度之星"程序设计大赛
    2018省赛赛第一次训练题解和ac代码
    2018天梯赛第一次训练题解和ac代码
    rsa Round #71 (Div. 2 only)
    AtCoder Grand Contest 021
    Hello 2018
    Educational Codeforces Round 36 (Rated for Div. 2)
    Codeforces Round #462 (Div. 2)
    Codeforces Round #467 (Div. 2)
    [Offer收割]编程练习赛48
  • 原文地址:https://www.cnblogs.com/slu182/p/4259601.html
Copyright © 2011-2022 走看看