我正在从枚举(垂直显示)中加载单选按钮列表。 我需要显示描述每个单选按钮选择的文本。 我正在代码隐藏中加载它。
最佳答案
最近我发现 Enum 类的很多方面的用途越来越多,其中之一就是 GetNames 方法。此方法返回指定枚举中所有名称的字符串数组。
此代码假定您的页面上有一个名为 RadioButtonList1 的 RadioButtonList。
public enum AutomotiveTypes
{
Car,
Truck,
Van,
Train,
Plane
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] automotiveTypeNames = Enum.GetNames(typeof(AutomotiveTypes));
RadioButtonList1.RepeatDirection = RepeatDirection.Vertical;
RadioButtonList1.DataSource = automotiveTypeNames;
RadioButtonList1.DataBind();
}
}
试一试,看看它是否适合你。
干杯!
关于c# - 从枚举加载单选按钮列表时,如何在每个单选按钮旁边显示文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/811693/