Is it possible to set requiredfieldvalidation on a dropdownlist with an Accessdatasource in a detailsview? I know it can be done programmatically when the items for the dropdownlist are done as follows:
<asp:DropDownList id=ddl runat="server"><asp:ListItem>First Item</asp:ListItem> <asp:ListItem>Second Item</asp:ListItem> <asp:ListItem>Third Item</asp:ListItem></asp:DropDownList>
How can I go about accomplishing this when the list items are coming from an AccessDataSource?
Thanks ahead of time!!!
it doesnt matter where the drop down list is getting its values from, just add a required field validator on your page and point it to the drop down list.
mcm
I've done that. Nothing happens. Where have I gone wrong?
<InsertItemTemplate>
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="false"DataSourceID="AccessDataSource12"
DataTextField="JobName"DataValueField="JobName"SelectedValue='<%# Bind("POJobNumber") %>'
Width="455px">
</asp:DropDownList>
<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ErrorMessage="Job Number is required"ControlToValidate="DropDownList1"InitialValue=""Font-Bold="true"/>
</InsertItemTemplate>
Any assistance would be greatly appreciated.
your binding selected value to the POJobnumber what values does this have initially ? like, is this an edit form or an insert form because if you are pulling data in, and binding POJobNumber to the ddl then the ddl techincally has a selected value so it would pass validation, if however this was inserting a record you would need to add an item to the top of the list (can be hard coded or added in on your databound event) this item should be blank, have no value, the text could be something like "--choose a value--" but the key is the value should be blank. This would be the initial selected item in the ddl and this will fail validation if nothing else is selected.
does this clear anythign up ?
hth,
mcm
Thanks!
I decided to go ahead and make my first records in the DB Null records. That cleared it right up! I kind of figured that it was passing validation being that there is info in the dropdown.
Thanks again!
No comments:
Post a Comment