2011-09-08 92 views
-2

我有嵌套的中繼器。並在兒童中繼器有一個下拉列表爲每個記錄。此下拉列表中包含靜態項目是1,2,3,現在我想檢查用戶無法從組中選擇一個值。實際上它是什麼。當我單擊在父母中繼器上,它將顯示包含與被點擊的父母記錄的ID匹配的記錄的子中繼器。現在在兒童中繼器中有由靜態值填充的下拉列表(1,2,3)。兒童中繼器只能顯示最多三條記錄。現在我想讓用戶無法從這個組中選擇兩次值。怎麼可能?請幫幫我。提前致謝。dropdownlist的**選定的值不能重複**

回答

0

你需要檢查驗證在保存像下面的數據的時間:

String[] arrSelectedValues = null; 
    foreach (RepeaterItem itemParent in rptTest.Items) 
    { 
     Repeater rptChild = (Repeater)itemParent.FindControl("rptChild"); 
     if (rptChild != null) 
     { 
      foreach (RepeaterItem item in rptChild.Items) 
      { 
       DropDownList ddlTest = (DropDownList)item.FindControl("ddlTest"); 
       if (arrSelectedValues.Contains(ddlTest.SelectedValue) 
       { 
        // Write code to fire validation here 
       } 
       else 
        arrSelectedValues.Add(ddlTest.SelectedValue); 
      } 
     } 
    }