ASP.NETバインドのドロップダウンボックスなどの方法(RadioButtonList 1,DropDownList 1…などのラジオリスト、ドロップダウンリストと同じように属性を調整すればよい)

9442 ワード

一.効果は簡単ですいくつかの属性はWinfromとほぼ同じです
Winfrom:
cobbox.DisplayMembe=“   ”
cobbox.ValueMember=”   ID”

1.デッドリンク:Winfromのいくつかの属性を1つずつ追加
public void BindCob()
        {
            cmbSex.Items.Add("---   ----");
            cmbSex.Items.Add(" ");
            cmbSex.Items.Add(" ");
            cmbSex.Text = "---   ----";
        }

2.オブジェクトコンストラクタセットを1つずつ追加
 public void cmbRolebind()
        {
            cmbRole.DisplayMember = "U_RealName";
            cmbRole.ValueMember = "U_Role";
            List Roles = new List();
            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 m1 = new List()
            {
               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();
        }