2015-07-16 2 views
0

Я пытаюсь добавить 3 переключателя в каждую ячейку таблицы, которую я создаю динамически, но они все позиционируют себя вне ячеек и выстраиваются в линию вверху с большей части страницы:asp.net добавить управление динамически в позицию

enter image description here

Я хочу, чтобы RadioButton был создан для размещения внутри ячейки таблицы. Как мне это сделать? Любая помощь будет оценена. Вот мой код:

   int count = 0; 
       int countRB = 0; 
       if (dataReader.HasRows) 
       {      
        testLabel1.Text = "dataReader.HasRows: " + dataReader.HasRows;     
        while (dataReader.Read()) 
        { 
         count += 1; 

      htmlString.Append("<table border = '1'>"); 
         htmlString.Append("<tr>"); 
         htmlString.Append("<td>");      

         for (int i = countRB; i < countRB + 3; i++) 
         { 
          RadioButton rb = new RadioButton(); 

          // Set the label's Text and ID properties. 
          rb.Text = "RadioButton" + (i+1).ToString(); 
          rb.ID = "RadioButton" + (i + 1).ToString(); 
          test_populatePlaceHolder.Controls.Add(rb); 
          // Add a spacer in the form of an HTML <br /> element. 
          test_populatePlaceHolder.Controls.Add(new LiteralControl("<br />")); 
         } 
         countRB = count * 3; 
         htmlString.Append(dataReader["dateTime"] + "<br />" + dataReader["statistics"]"); 
      htmlString.Append("</td>"); 
         htmlString.Append("</tr>"); 
         htmlString.Append("</table>"); 
         htmlString.Append("<br />"); 
        }     
        test_populatePlaceHolder.Controls.Add(new Literal { Text = htmlString.ToString() }); 
        dataReader.Close(); 
        dataReader.Dispose(); 
       }     
      } 
     } 
    } 

ответ

1

Почему бы не просто добавить кнопку радио, как:

<span><input type="radio" id="rd1" />SOMTEXT </span> 

Так что в вашем коде:

for (int i = countRB; i < countRB + 3; i++) 
        { 
string tmptxt="<span><input type=\"radio\" id=\"RadioButton" + (i+1).ToString()\" />"RadioButton" + (i+1).ToString()</span>"; 

htmlString.Append(tmptxt) 
} 
+1

Ну поставил и очень просто. Благодарю. – matt2605

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