Setting dropdownlist selecteditem programmatically

前端 未结 11 1725
北海茫月
北海茫月 2020-11-28 07:47

I want to set the selecteditem attribute for an ASP.Net dropdownlist control programmatically.

So I want to pass a value to the dropdownlist control to

11条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 08:28

    On load of My Windows Form the comboBox will display the ClassName column of my DataTable as it's the DisplayMember also has its ValueMember (not visible to user) with it.

    private void Form1_Load(object sender, EventArgs e)
                {
                    this.comboBoxSubjectCName.DataSource = this.Student.TableClass;
                    this.comboBoxSubjectCName.DisplayMember = TableColumn.ClassName;//Column name that will be the DisplayMember
                    this.comboBoxSubjectCName.ValueMember = TableColumn.ClassID;//Column name that will be the ValueMember
                }
    

提交回复
热议问题