繁体   English   中英

asp.net动态添加控件到位置

[英]asp.net add control dynamically to position

我试图将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();
                }                
            }
        }
    }

为什么不简单地添加单选按钮,例如:

<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)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM