2016-06-15 52 views
0

有谁知道如何验证中继器内的多个下拉列表?似乎无法找到网上的任何文章。我需要验证,第一个下拉文本与第二个下拉文本不同,等等。如何验证中继器内的多个下拉列表

+0

寻找客户端验证,jQuery? – Sami

+0

我不介意。但更喜欢服务器端。 – e0001304

回答

0

当您在寻找服务器端解决方案时。我们假设通过单击按钮进行验证,遍历中继器项目,在List中查找下拉列表和值。

List<string> ddlValues = new List<string>(); 

foreach (RepeaterItem item in rptItems.Items) 
{ 
    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) 
    { 
     DropdownList ddl = (DropdownList)item.FindControl("YourDropdown"); 
     ddlValues.Add(ddl.SelectedValue); 
    } 
} 


//Get duplicate values count 
var duplicateKeys = list.GroupBy(x => x) 
        .Where(group => group.Count() > 1) 
        .Select(group => group.Key); 

if (duplicateKeys.Count>0) {} // duplicate values found . Do you stuff now 
+0

希望这会有所帮助,并给你一个想法 – Sami