2013-08-01 4 views
1

добавить элемент списка Asp.net между ячейками таблицы. Когда я пытаюсь добавить список Radiobutton List, список всех элементов списка, идущих последним td цикла. Но я хочу сделать каждый элемент списка в моем внутреннем цикле td. Я добавил код ниже. Мой снимок экрана ниже. Может кто-нибудь, пожалуйста, помогите мне в этом. enter image description hereДобавить элемент RadioButtonList в td, используя цикл

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

        } 
       } 

ответ

0

Bind данных в сетке. Используйте radobutton как itemtemplate. Укажите название радиообъекта в элементе itemtemplate.

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

       } 
      } 
     } 
Смежные вопросы