C# RadioButtonList 到 TableCells
我正在尝试将单选按钮添加到我的表格中。
问题是我正在使用 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;
}
I'm trying to add radio buttons to my Table.
The problem is that I'm using a RadioButtonList to hold radios and an ListItem cant be added to a cell for some reason? Is my code totally of or is there another way to handle this in .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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ListItem 直接属于 RadioButtonList(或某些其他 ASP.Net 列表控件)。您可以尝试使用普通的 HtmlInputRadioButton具有指定的 名称 将它们链接在一起。
A ListItem belongs directly in a RadioButtonList (or some other ASP.Net list control). You could try to use plain HtmlInputRadioButton with a specified Name to link them together.