C # RadioButtonList в табличные ячейки

#c# #webforms #controller #radiobuttonlist

#c# #веб-формы #контроллер #radiobuttonlist

Вопрос:

Я пытаюсь добавить переключатели в свою таблицу.

Проблема в том, что я использую RadioButtonList для хранения радиостанций, и по какой-то причине ListItem не может быть добавлен в ячейку? Полностью ли мой код соответствует или есть другой способ справиться с этим в .net?

 private TableRow generateCells(String domainName)
        {
            TableRow row = new TableRow();

            Label dName = new Label();
            dName.Text = domainName; 

            RadioButtonList radioList = new RadioButtonList();

            ListItem sunriseA = new ListItem();
            sunriseA.Value = Price_Types.SUNRISE_ONE.ToString();            
            radioList.Items.Add(sunriseA);

            ListItem sunriseB = new ListItem();
            sunriseB.Value = Price_Types.SUNRISE_TWO.ToString();
            radioList.Items.Add(sunriseB);

            ListItem landrush = new ListItem();
            landrush.Value = Price_Types.LANDRUSH.ToString();
            radioList.Items.Add(landrush);

            ListItem general = new ListItem();
            general.Value = Price_Types.GENERAL.ToString();
            radioList.Items.Add(general);

            row.Cells.Add(addCell(dName));
            // this is not working
            row.Cells.Add(addCell(sunriseA));
            row.Cells.Add(addCell(sunriseB));
            row.Cells.Add(addCell(landrush));
            row.Cells.Add(addCell(general));

            return row;

        }

        private TableCell addCell(Control c)
        {
            TableCell cell = new TableCell();
            cell.Controls.Add(c);
            return cell;
        }
  

Ответ №1:

Элемент списка принадлежит непосредственно RadioButtonList (или какому-либо другому ASP.Net управление списком). Вы могли бы попробовать использовать обычный htmlputradiobutton с указанным именем, чтобы связать их вместе.