我正在尝试在我动态创建的每个表格单元格中添加3个单选按钮,但它们都将自己定位在单元格之外,并从页面的最顶部排列:
我希望创建的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();
}
}
}
}
答案 0 :(得分: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)
}