[英]ASP.net looping through controls in a table
我有一個表,其中包含一堆動態創建的單選按鈕列表,我試圖編寫代碼,該代碼將遍歷每個單選按鈕列表並獲取所選項目的文本值。 我有以下代碼
foreach ( Control ctrl in Table1.Controls)
{
if (ctrl is RadioButtonList)
{
//get the text value of the selected radio button
}
}
但我仍然堅持如何獲取給定控件的所選項目的價值。
嘗試這個:
foreach (Control ctrl in Table1.Controls)
{
if (ctrl is RadioButtonList)
{
RadioButtonList rbl = (RadioButtonList)ctrl;
for (int i = 0; i < rbl.Items.Count; i++)
{
if (rbl.Items[i].Selected)
{
//get the text value of the selected radio button
string value = rbl.Items[i].Text;
}
}
}
}
若要確定RadioButtonList控件中的選定項目,請遍歷Items集合並測試該集合中每個項目的Selected屬性。
在這里查看: RadioButtonList Web服務器控件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.