簡體   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