在表格单元格之间添加Asp.net List Item。当我尝试添加Radiobutton列表所有列表项目来自循环的最后一个td。但是我想在我的td内部循环中创建每个List项。我已附上以下代码。我的输出截图如下。任何人都可以帮我这个。
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++;
}
}
答案 0 :(得分:0)
将数据绑定到网格。使用radiobutton作为itemtemplate。在itemtemplate中指定radiobutton的名称。
答案 1 :(得分:0)
试试这个
{
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'><input type='radio' value='"+dr["amount"].ToString()+"' name='test'/></td></tr>"));
}
RadioButtonList1.SelectedIndex = 0;
PlaceHolder1.Controls.Add(new LiteralControl("</table>"));
a++;
}
}
}