c#.net如何获取HtmlGenricControll来显示RadioButtonList项
本文关键字:HtmlGenricControll 显示 RadioButtonList 获取 net 何获取 | 更新日期: 2023-09-27 17:57:57
我有一个HtmlGenericController,我想添加RadioButtons。我的单选按钮来自RadioButtonList,因此对象是Listitems。如何让我的泛型控制器显示单选按钮?
这是我的代码
private HtmlGenericControl generateCells(String domainName)
{
HtmlGenericControl container = new HtmlGenericControl("div");
HtmlGenericControl dName = new HtmlGenericControl("span");
dName.InnerHtml = domainName;
RadioButtonList radioList = new RadioButtonList();
radioList.ID = "radio_" + domainName;
radioList.RepeatDirection = RepeatDirection.Horizontal;
ListItem sunriseA = new ListItem();
sunriseA.Value = Price_Types.SUNRISE_ONE.ToString();
//sunriseA.Text = Price_Types.SUNRISE_ONE.ToString();
sunriseA.Text = "";
radioList.Items.Add(sunriseA);
ListItem sunriseB = new ListItem();
sunriseB.Value = Price_Types.SUNRISE_TWO.ToString();
//sunriseB.Text = Price_Types.SUNRISE_TWO.ToString();
sunriseB.Text = "";
radioList.Items.Add(sunriseB);
ListItem landrush = new ListItem();
landrush.Value = Price_Types.LANDRUSH.ToString();
//landrush.Text = Price_Types.LANDRUSH.ToString();
landrush.Text = "";
radioList.Items.Add(landrush);
ListItem general = new ListItem();
general.Value = Price_Types.GENERAL.ToString();
//general.Text = Price_Types.GENERAL.ToString();
general.Text = "";
radioList.Items.Add(general);
container.Controls.Add(dName);
foreach (ListItem item in radioList.Items)
{
HtmlGenericControl span = new HtmlGenericControl("span");
span.InnerHtml = item;//what to put here??
container.Controls.Add(span);
}
return container;
}
var radioButton = new HtmlGenericControl("input");
radioButton.Attributes["type"] = "radio";
radioButton.Attributes["name"] = "groupName";
radioButton.Attributes["value"] = "buttonValue";
不过,这只会渲染圆形单选按钮本身。要添加标签,除了span
之外,还必须渲染它。或者,IIRC,渲染label
字段,其中for
属性设置为单选按钮的ID,因此单击标签也会自动单击按钮。