0

我有一个 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;

        }
4

1 回答 1

2
var radioButton = new HtmlGenericControl("input");
radioButton.Attributes["type"] = "radio";
radioButton.Attributes["name"] = "groupName";
radioButton.Attributes["value"] = "buttonValue";

不过,这只会呈现圆形单选按钮本身。要添加标签,您必须在旁边渲染例如 a span。或者,IIRC,呈现一个属性设置为单选按钮 ID 的label字段for,因此单击标签也会自动单击按钮。

于 2011-05-31T08:15:50.947 回答