2010-05-13 33 views

回答

2

您必须在DataBind()DropDownList之前传递要分配给DataTextField和DataValueField的字段的字符串名称。

实施例:

protected void populateDropDownList(){ 
    IList<MyObject> myObjectList = getMyObjectList(); 

    DropDownList1.DataSource = myObjectList; 
    DropDownList1.DataTextField = "FullName"; // exact name of field in class 
    DropDownList.DataValueField = "id"; 

    DropDownList.DataBind(); 

}