1

在表格单元格之间添加 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>&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'>"));



                            //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++;

                    }
                }
4

2 回答 2

0

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

于 2013-08-01T07:44:55.990 回答
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>&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++;

                }
            }
        }
于 2013-08-01T07:49:00.643 回答