我不确定这是否可行,但我有一个复杂类型的字典,我想将它绑定(bind)到 RadioButtonList/CheckBoxList 控件:
public class ComplexType
{
public String Name { get; set; }
public String FormattedName { get; set; }
public String Description { get; set; }
}
var listOfMyTypes = new Dictionary<int, ComplexType>();
var myType = new ComplexType { Name = "Name", Description = "Description", FormattedName = "Name|Description" };
var myType1 = new ComplexType { Name = "Name2", Description = "Description2", FormattedName = "Name|Description2" };
listOfMyTypes.Add(1, myType);
listOfMyTypes.Add(2, myType1);
m_dropDownlist.DataTextField = "Value"; //What do I put here to render "Name"
m_dropDownlist.DataValueField = "Key";
m_dropDownlist.DataSource = listOfMyTypes;
m_dropDownlist.DataBind();
最佳答案
尝试像这样绑定(bind)到 Dictionary.Values
:
m_dropDownlist.DataTextField = "Name"
m_dropDownlist.DataValueField = "Description";
m_dropDownlist.DataSource = listOfMyTypes.Values;
m_dropDownlist.DataBind();
关于c# - 将复杂类型的字典绑定(bind)到 RadioButtonList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11274523/