码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET 绑定的下拉框等方法(RadioButtonList1,DropDownList1...等单选列表,下拉列表同理调整属性即可)

时间:2020-02-22 09:42:42      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:效果   bsp   sel   isp   显示   相同   use   usermod   ber   

一.效果很简单几个属性与Winfrom 几乎相同

Winfrom:

cobbox.DisplayMembe=“显示值”
cobbox.ValueMember=”绑定值ID”

1.死绑:Winfrom几个属性一个一个添加

public void BindCob()
        {
            cmbSex.Items.Add("---请选择----");
            cmbSex.Items.Add("");
            cmbSex.Items.Add("");
            cmbSex.Text = "---请选择----";
        }

2.对象构造器集合一个一个添加

 public void cmbRolebind()
        {
            cmbRole.DisplayMember = "U_RealName";
            cmbRole.ValueMember = "U_Role";
            List<UserModel> Roles = new List<UserModel>();
            Roles.Add(new UserModel() { S_ID = 2, U_LoginName = "A2", U_Password = "123456", U_RealName = "管理员", U_Sex = "", U_Telephone = "1234566666", U_Role = 1, U_CanDelete = false });
            Roles.Add(new UserModel() { S_ID = 2, U_LoginName = "A2", U_Password = "123456", U_RealName = "店长", U_Sex = "", U_Telephone = "1234566666", U_Role = 2, U_CanDelete = false });
            Roles.Add(new UserModel() { S_ID = 2, U_LoginName = "A2", U_Password = "123456", U_RealName = "营业员", U_Sex = "", U_Telephone = "1234566666", U_Role = 3, U_CanDelete = false });
            //foreach (var Role in Roles)
            //{
            //    cmbRole.Items.Add(Role);
            //}
            cmbRole.DataSource = Roles;
            cmbRole.SelectedIndex = 0;
        }

3.活的数据库;上面是一个数据库的方法

 public void binlist()
        {
            string sql = "select * from Users";
            DataTable dt = db.selectdt(sql, null, false);
            combox.DataSource = dt;
            combox.DisplayMember = "U_RealName";
            combox.ValueMember = "U_ID";
        }    
winfrom

 

二,1.ASP.NET类似:死绑

  public void bindrdolist()
        {
            List<Mylist> m1 = new List<Mylist>()
            {
               new Mylist(){id=1,name="2"},
               new Mylist(){id=3,name="3"},
               new Mylist(){id=4,name="4"}
            };
            RadioButtonList1.DataSource = m1;
            RadioButtonList1.DataTextField = "name";
            RadioButtonList1.DataValueField = "id";
            RadioButtonList1.DataBind();
        }

2.活绑

  public void binlist()
        {
            string sql = "select * from Users";
            DataTable dt = db.selectdt(sql, null, false);
            DropDownList1.DataSource = dt;
            DropDownList1.DataTextField = "U_RealName";
            DropDownList1.DataTextField = "U_ID";
            DropDownList1.DataBind();
        }      

 

ASP.NET 绑定的下拉框等方法(RadioButtonList1,DropDownList1...等单选列表,下拉列表同理调整属性即可)

标签:效果   bsp   sel   isp   显示   相同   use   usermod   ber   

原文地址:https://www.cnblogs.com/yijieyufu/p/12343914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!