在Asp.Net 3.5中,DataValueField可能是IList?Asp.Net - IList中的DropDownList.DataValueField
myddl.DataValueField = "ListOfId"
其中ListOfId在我的数据源
在Asp.Net 3.5中,DataValueField可能是IList?Asp.Net - IList中的DropDownList.DataValueField
myddl.DataValueField = "ListOfId"
其中ListOfId在我的数据源
一个IList中这是不可能的。 DataValueField必须是一个字符串,即绑定的数据源的公共属性的名称:
如果你有字符串的一个简单的列表,你可以只是把它绑定到下拉:
您必须在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();
}