dropdownlist's **selected values cannot be duplicate**
I have nested repeater. And in child repeater there is a dropdownlist for each record.This dropdown contains static items that is 1,2,3 and now i want to check the user cannot selected a value twice from a group.Actually what is it..When i click on parent repeater it will show child repeater which contains records matched to the ID of parent record clicked. Now in child repeater there is dropdownlist filled by static values (1,2,3). And the child repeater can show max three records only. now i want a user cannot select a value twice from this group. how it will possible? Please h开发者_JAVA技巧elp me. Thanks in advance.
You need to check that validation at the time of save data like below :
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);
}
}
}
精彩评论