gpt4 book ai didi

c# - 将复杂类型的字典绑定(bind)到 RadioButtonList

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:17 27 4
gpt4 key购买 nike

我不确定这是否可行,但我有一个复杂类型的字典,我想将它绑定(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com