C# 使用循环在td中添加RadioButtonList项

C# 使用循环在td中添加RadioButtonList项,c#,jquery,html,asp.net,C#,Jquery,Html,Asp.net,在表单元格之间添加Asp.net列表项。当我尝试添加Radiobutton时,列出循环最后一个td的所有列表项。但我想让它成为我的td-inside循环中的每个列表项。我在下面附上了代码。下面是我的输出截图。谁能帮我一下吗。 var noofroom=(来自dt2.AsEnumerable()中的第2行) 其中(Int64)第2行[“hotelcode”]==hotelcode 选择row2.Field(“来宾”).Distinct(); var noofroom2=(来自dt2.AsEnum

在表单元格之间添加Asp.net列表项。当我尝试添加Radiobutton时,列出循环最后一个td的所有列表项。但我想让它成为我的td-inside循环中的每个列表项。我在下面附上了代码。下面是我的输出截图。谁能帮我一下吗。

var noofroom=(来自dt2.AsEnumerable()中的第2行)
其中(Int64)第2行[“hotelcode”]==hotelcode
选择row2.Field(“来宾”).Distinct();
var noofroom2=(来自dt2.AsEnumerable()中的第3行)
其中(Int64)第3行[“hotelcode”]==hotelcode
选择row3.Field(“noofrom”).Distinct();
INTA=1;
foreach(noofroom中的var r r计数)
{
foreach(noofroom2中的var rcount2)
{
DataRow[]drs=dt2。选择(“hotelcode=”“+hotelcode+”,noofroom=”“+rcount2+”,guests=”“+rcount+””;
int numberOfRecords=dt2。选择(“hotelcode=”“+hotelcode+”,noofroom=”“+rcount2+”,guests=”“+rcount+”)。长度;
如果(numberOfRecords!=0)
{
占位符1.Controls.Add(新的LiteralControl(“”)+
“房间+a+”+
"" +
"" +
"" +
"" +
“”+
“板类型”+
"" +
“”+
“房间类型”+
"" +
“房价”+
"" +
“”+
“睡到”+
"" +
“”+
""));
}
RadioButtonList RadioButtonList1=新的RadioButtonList();
RadioButtonList1.ID=hotelcode.ToString()+rcount.ToString()+rcount2.ToString();
foreach(drs中的数据行dr)
{
占位符1.Controls.Add(新的LiteralControl(“”)+
"" +
" " +
“+dr[“板”]+”+
"" +
“+dr[“roomtype”]+”+
"" +
" " +
“£”+dr[“金额”]”+
"" +
" " +
“+dr[“来宾”]+“来宾”+
""));
//RadioButtonList1.ID=hotelcode.ToString();
ListItem li=新的ListItem();
li.Value=dr[“amount”].ToString();
li.Text=“”;
RadioButtonList1.项目.添加(li);
占位符1.控件.添加(RadioButtonList1);
占位符1.Controls.Add(新的LiteralControl(“”)+
"" +
""));
}
RadioButtonList1.SelectedIndex=0;
占位符1.Controls.Add(新的LiteralControl(“”);
a++;
}
}

将数据绑定到网格。使用radiobutton作为项目模板。在itemtemplate中指定radiobutton的名称。

试试这个

{
            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>&nbsp;" +
                        "Board Type</strong></td>" +
                        "<td class='style30'>" +
                            "<strong>&nbsp;" +
                        "Room Type</strong></td>" +
                        "<td class='tdaltbg'>" +
                            "<strong>&nbsp;&nbsp; Room Price</strong></td>" +
                            "<td class='style30'>" +
                            "<strong>&nbsp;" +
                        "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'>" +
                                 "&nbsp;" +
                                 "" + dr["board"] + "</td>" +
                            "<td class='style30'>" +
                                 "" + dr["roomtype"] + "</td>" +
                             "<td class='tdaltbg'>" +
                                 "&nbsp;" +
                                 "£ " + dr["amount"] + "</span></td>" +
                                   "<td class='style30'>" +
                                 "&nbsp;" +
                                 " " + 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++;

                }
            }
        }
{
var noofroom=(来自dt2.AsEnumerable()中的第2行)
其中(Int64)第2行[“hotelcode”]==hotelcode
选择row2.Field(“来宾”).Distinct();
var noofroom2=(来自dt2.AsEnumerable()中的第3行)
其中(Int64)第3行[“hotelcode”]==hotelcode
选择row3.Field(“noofrom”).Distinct();
INTA=1;
foreach(noofroom中的var r r计数)
{
foreach(noofroom2中的var rcount2)
{
DataRow[]drs=dt2。选择(“hotelcode=”“+hotelcode+”,noofroom=”“+rcount2+”,guests=”“+rcount+””;
int numberOfRecords=dt2。选择(“hotelcode=”“+hotelcode+”,noofroom=”“+rcount2+”,guests=”“+rcount+”)。长度;
如果(numberOfRecords!=0)
{
占位符1.Controls.Add(新的LiteralControl(“”)+
“房间+a+”+
"" +
"" +
"" +
"" +
“”+
“板类型”+
"" +
“”+
“房间类型”+
"" +
“房价”+
"" +
“”+
“睡到”+
"" +
“”+
""));
}
RadioButtonList RadioButtonList1=新的RadioButtonList();
RadioButtonList1.ID=hotelcode.ToString()+rcount.ToString()+rcount2.ToString();
foreach(drs中的数据行dr)
{
占位符1.Controls.Add(新的LiteralControl(“”)+
"" +
{
            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>&nbsp;" +
                        "Board Type</strong></td>" +
                        "<td class='style30'>" +
                            "<strong>&nbsp;" +
                        "Room Type</strong></td>" +
                        "<td class='tdaltbg'>" +
                            "<strong>&nbsp;&nbsp; Room Price</strong></td>" +
                            "<td class='style30'>" +
                            "<strong>&nbsp;" +
                        "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'>" +
                                 "&nbsp;" +
                                 "" + dr["board"] + "</td>" +
                            "<td class='style30'>" +
                                 "" + dr["roomtype"] + "</td>" +
                             "<td class='tdaltbg'>" +
                                 "&nbsp;" +
                                 "£ " + dr["amount"] + "</span></td>" +
                                   "<td class='style30'>" +
                                 "&nbsp;" +
                                 " " + 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++;

                }
            }
        }