Like we keep blank textboxes for user to enter something need to do same for dropdown lists too. For this we add an item i.e. “Select”, “Select an item” this indicates that user not selected any thing from dropdown and also indication he/she need to select from given list, so lets do it first and then we will apply validation on it
In your dropdown set AppendDataBoundItems="True" property to true. This property controls whether the items within an existing list are replaced or appended-to when the control is data bounded.
private void FillServices()
{
ddlServices.Items.Clear();
ddlServices.Items.Add(new ListItem("Select", "0"));
ddlServices.DataSource = FilterServices(((customers)Session[SessionTypes.Customer]).services);
ddlServices.DataTextField = "name";
ddlServices.DataValueField = "id";
ddlServices.DataBind();
}
Now, apply validation on our dropdown list as below
Download Article
No comments:
Post a Comment