0
A
回答
0
客户端比较:
<script type="text/javascript">
function CompareSelectedValues(dropDown1ID, dropDown2ID) {
var DropDownList1 = document.getElementById(dropDown1ID);
var DropDownList2 = document.getElementById(dropDown2ID);
if (DropDownList1.selectedIndex != -1 && DropDownList2.selectedIndex != -1) {
if (DropDownList1.options[DropDownList1.selectedIndex].value != DropDownList2.options[DropDownList2.selectedIndex].value)
alert('not same');
}
}
</script>
经典服务器端与C#比较:
private bool AreDropDownListValuesEqual(DropDownList ddlist1, DropDownList ddlist2)
{
// Check for invalid input or different number of items for early return
if (ddlist1 == null || ddlist2 == null || ddlist1.Items.Count != ddlist2.Items.Count)
{
return false;
}
// Check items one by one. We need a nested loop because the list could be sorted differently while having the same values!
foreach (ListItem outerItem in ddlist1.Items)
{
bool hasMatch = false;
foreach (ListItem innerItem in ddlist2.Items)
{
if (innerItem.Value == outerItem.Value && innerItem.Text == outerItem.Text)
{
hasMatch = true;
break;
}
}
if (!hasMatch)
{
return false;
}
}
// All items from ddlist1 had a match in ddlist2 and we know that the number of items is equal, so the 2 dropdownlist are matching!
return true;
}
0
你需要什么样的比较?如果您没有将它们保留在会话中的列表和列表中,那么您将无法对它们进行任何操作,因为它们是动态添加的。添加你创建它们的下拉列表(这应该是我在Page.IsPostBack == false时)并在会话中保留该列表。在回传时,从列表中加载您的下拉列表。您可以使用您保留的列表进行比较。
相关问题
- 1. 比较比较Int
- 2. jquery DropDownLists
- 3. 比较比较器的utils
- 4. 比较无法比较
- 5. DropDownLists值重置
- 6. Gridviews和DropdownLists
- 7. MVC中的DropdownLists
- 8. 级联DropDownLists
- 9. Multiple DropDownLists Jquery
- 10. EntityDataSource,QueryCreated和DropDownLists
- 11. UpdatePanels和DropDownLists
- 12. 我有dropdownLists
- 13. 比较器/比较/比较器链接问题
- 14. 比较
- 15. 比较
- 16. 比较
- 17. 比较
- 18. 比较
- 19. 比较
- 20. 比较
- 21. 比较
- 22. 比较
- 23. 比较
- 24. 比较
- 25. 比较
- 26. 比较
- 27. 比较
- 28. 比较
- 29. 比较
- 30. 比较