Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 3 dropdown list in a page, i want to validate that if i select two or more dropdown list at a time it alert message "select only one value"
Posted

1 solution

C#
protected void Page_Load(object sender, EventArgs e)
{
  CheckForMoreThanOneSelectedItem();

}

protected void CheckForMoreThanOneSelectedItem()
{
  bool MoreThanOneSelected = false;
  if(ddl1.SelectedIndex != 0 &&( ddl2.SelectedIndex !=0 ||ddl3.SelectedIndex != 0) )
  {
    MoreThanOneSelected = true;
  }
  if(ddl2.SelectedIndex != 0 &&( ddl1.SelectedIndex !=0 ||ddl3.SelectedIndex != 0) )
  {
    MoreThanOneSelected = true;
  }
  if(ddl3.SelectedIndex != 0 &&( ddl1.SelectedIndex !=0 ||ddl2.SelectedIndex != 0) )
  {
    MoreThanOneSelected = true;
  }

  if(MoreThanOneSelected==true)
  {
    Alret The Message
  }
}






it might not be the best answer...but try it and let me know if it works,
make sure to set the AutoPostBack Propertie of your three DropDownLists to True
 
Share this answer
 
v3
Comments
Ashi0891 17-Aug-14 0:14am    
Though the above answer is very correct, in case you want to give different alert message on different control then you can put the code inside DropDownList_SelectedIndexChanged event of every dropdownlist.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900