簡體   English   中英

c#.net 如何獲取 HtmlGenricControll 以顯示 RadioButtonList 項

[英]c#.net how to get a HtmlGenricControll to show a RadioButtonList item

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

不過,這只會呈現圓形單選按鈕本身。 要添加 label,您必須在旁邊渲染一個span 或者,IIRC,渲染一個label字段並將for屬性設置為單選按鈕的 ID,因此單擊 label 也會自動單擊該按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM