在表格单元格之间添加 Asp.net 列表项。当我尝试添加单选按钮列表时,所有列表项都在循环的最后一个 td 中。但我想让它在我的 td inside 循环中成为每个列表项。我在下面附上了代码。我的输出截图如下。谁能帮我解决这个问题。
var noofroom = (from row2 in dt2.AsEnumerable()
where (Int64)row2["hotelcode"] == hotelcode
select row2.Field<string>("guests")).Distinct();
var noofroom2 = (from row3 in dt2.AsEnumerable()
where (Int64)row3["hotelcode"] == hotelcode
select row3.Field<string>("noofroom")).Distinct();
int a = 1;
foreach (var rcount in noofroom)
{
foreach (var rcount2 in noofroom2)
{
DataRow[] drs = dt2.Select("hotelcode='" + hotelcode + "' AND noofroom='" + rcount2 + "' and guests='"+rcount+"'");
int numberOfRecords = dt2.Select("hotelcode='" + hotelcode + "' AND noofroom='" + rcount2 + "' and guests='" + rcount + "'").Length;
if (numberOfRecords != 0)
{
PlaceHolder1.Controls.Add(new LiteralControl("<div class='rhead'>" +
"Room " + a + "" +
"</div>" +
"<table class='roomtbl'>" +
"<tr>" +
"<td class='tdaltbg'>" +
"<strong> " +
"Board Type</strong></td>" +
"<td class='style30'>" +
"<strong> " +
"Room Type</strong></td>" +
"<td class='tdaltbg'>" +
"<strong> Room Price</strong></td>" +
"<td class='style30'>" +
"<strong> " +
"Sleep Up To</strong></td>" +
"<td class='tdaltbg'>" +
"<strong></strong></td>" +
"</tr>"));
}
RadioButtonList RadioButtonList1 = new RadioButtonList();
RadioButtonList1.ID = hotelcode.ToString() + rcount.ToString()+rcount2.ToString();
foreach (DataRow dr in drs)
{
PlaceHolder1.Controls.Add(new LiteralControl("<tr>" +
"<td class='tdaltbg'>" +
" " +
"" + dr["board"] + "</td>" +
"<td class='style30'>" +
"" + dr["roomtype"] + "</td>" +
"<td class='tdaltbg'>" +
" " +
"£ " + dr["amount"] + "</span></td>" +
"<td class='style30'>" +
" " +
" " + dr["guests"] + " Guests</span></td>" +
"<td class='tdaltbg'>"));
//RadioButtonList1.ID = hotelcode.ToString();
ListItem li = new ListItem();
li.Value = dr["amount"].ToString();
li.Text = "";
RadioButtonList1.Items.Add(li);
PlaceHolder1.Controls.Add(RadioButtonList1);
PlaceHolder1.Controls.Add(new LiteralControl("" +
"</td>" +
"</tr>"));
}
RadioButtonList1.SelectedIndex = 0;
PlaceHolder1.Controls.Add(new LiteralControl("</table>"));
a++;
}
}