Search code examples
c#asp.netdrop-down-menu

Dropdownlist Validation with Submit Button in ASP.NET C#


I have a dropdownlist with below values and Submit button at bottom of page

  • China
  • Japan
  • England

I have this dropdownlist placed in gridview and display the listitem accordingly to the rows. But I have a condition where If the value is China in any row in gridview Then user should be promted with an error message when click on Submit button. Else if any of the rows are not china, then user should proceed.


Solution

  • Something like that

     foreach (GridViewRow row in this.gridView.Rows)
     {
        DropDownList ddl = row.FindControl("ddlName") as DropDownList;
        if(ddl != null)
        {
        //check here
        }
     }