2009-09-30 63 views
0

我有一個列表視圖,每列有兩個或多個單選按鈕控件,我想查找是否至少有一個單選按鈕被提交。.net listview查找是否至少有一個radiah在eah列中被選中

例如

ROW 1 Quetison 1 radiobutton1 radiobutton2 radiobutton3

ROW 2 Quetison 2 radiobutton1 radiobutton2 radiobutton3

上提交我想findout如果用戶檢查ATLEAST每個ROW上一個單選按鈕

+0

http://stackoverflow.com/questions/1497414/getting - 從一個選定的項目在一個單選項在一個網格視圖中的asp-n/1497511#1497511 –

+0

asp.net listview – nLL

回答

3

了一個Asp.Net的ListView:

foreach(ListViewDataItem myItem in myListView.Items) 
{ 
    RadioButton btn1 = (RadioButton)myItem.FindControl("radiobutton1"); 
    RadioButton btn2 = (RadioButton)myItem.FindControl("radiobutton2"); 
    RadioButton btn3 = (RadioButton)myItem.FindControl("radiobutton3"); 

    bool AtLeastOneChecked = btn1.Checked || btn2.Checked || btn3.Checked; 

} 

新方法 - 不知道的單選按鈕#

foreach(ListViewDataItem myItem in myListView.Items) 
{ 
    bool AtLeastOneChecked = false; 
    foreach(Control myControl in myItem.Controls) 
    { 
     try 
     { 
     RadioButton rdoTemp = (RadioButton)myControl; 
     AtLeastOneChecked = rdoTemp.Checked; 
     } 
     catch (Exception) 
     { 
      // do nothing - this probably wasn't a radio button control and errored out onthe conversion 
     } 
    }  
} 
+0

謝謝,這看起來很有前途,但我的問題是我不知道單選按鈕的數量。我只知道最大單選按鈕數(它是5) – nLL

+0

它看起來像它的工作,即使單選按鈕的數量不同於foreach循環中的那些感謝 – nLL

相關問題