You can use RequiredFieldValidator for DropDownList.
Just select InitialValue of the RequiredFieldValidator to -1 or 0 whatever that you select for the first element (often with text "Please Select") of DropDownList. Now validator will work and you need to select any other value than the InitialValue in order to pass validation.
ASP.NET, C#.NET, CruiseControl.NET, Microsoft SQL Server, MS-DOS Batch, MySQL, nAnt, NodeJs, PowerShell, Python, Selenium RC, Redis, WebAii, Ubuntu
Tuesday, June 24, 2008
Tuesday, June 17, 2008
Default Item for the DropDownList
You can bind C# dropdownlist to datasource and then assign the default value to it using following syntax. By default the 0th item is selected but you can specify it explicitly if you want to select item at different location.
dropDownList.Items.Insert(0,"Please Select"); // Inserts at the first location
dropDownList.Items[0].Selected = true; // First location is selected
dropDownList.Items.Insert(0,"Please Select"); // Inserts at the first location
dropDownList.Items[0].Selected = true; // First location is selected
Subscribe to:
Posts (Atom)