ASP.NET入门教程
1,首先,绑定了数据库教程中的一个“nclass表”
show sourceview sourceprint?1 dataset ds = getdataset("select * from nclass");2 this.combobox1.displaymember = "classname";
3 this.combobox1.valuemember = "classid";
4 this.combobox1.datasource = ds.tables[0];
“displaymember”属性:用自己最通俗的话来说,就是要显示给用户看的,绑定数据库中表“nclass”的“classname”字段;
“valuemember”属性:获取或设置一个属性的值,该值绑定为数据库中表“nclass”的“classid”字段;
dataset ds = getdataset("select * from nclass");
this.combobox1.displaymember = "classname";
this.combobox1.valuemember = "classid";
this.combobox1.datasource = ds.tables[0];
2,测试combobox选中后,相应属性是什么样的值:
show sourceview sourceprint?1 debug.writeline(this.combobox1.selectedindex); 2 3 debug.writeline(this.combobox1.selectedvalue.tostring()); 4 5 debug.writeline(this.combobox1.text); 6 7 debug.writeline(this.combobox1.selecteditem.gettype()); this.combobox1.selectedindex:如果此时选中的是combobox中第一个下拉选项,则该属性是获取当前第一个下拉选项的索引值,我这边索引值为“0”,依次递增;
this.combobox1.selectedvalue:该属性获得的是数据库中表“nclass”的“classid”字段对应的值;
debug.writeline(this.combobox1.selectedindex);
debug.writeline(this.combobox1.selectedvalue.tostring());
debug.writeline(this.combobox1.text);
debug.writeline(this.combobox1.selecteditem.gettype());
this.combobox1.text:该属性获取当前下拉菜单中选定的文本内容;
this.combobox1.selecteditem.gettype():该属性获取当前下拉菜单选择的每一行对象是什么类型
补充:asp.net教程,.Net开发