I have a DropDownList in my asp.net web page.
The RequiredFieldValidator is not working. Thanks for looking at my code.
<asp:DropDownList ID="Organization" runat="server"
DataSourceID="OrganizationList"
DataTextField="OrgName" DataValueField="OrgCode" CausesValidation="True">
</asp:DropDownList>
<asp:SqlDataSource ID="OrganizationList" runat="server"
ConnectionString="<%$ ConnectionStrings:MembershipDB %>"
SelectCommand="Admin_GetOrganizationDropDown"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidatorOrg"
ControlToValidate="Organization"
ErrorMessage="Organization is required."
Display="Dynamic" />
If you have not allready done it you should have a value that means that you are not selecting anything. Like this:
And then you need to tell the
asp:RequiredFieldValidatorto check for a value that you are not allowing. So InitialValue value should be 0. Like this:Then when the
--Select--option is chosen and you try to submit the page. Theasp:RequiredFieldValidatorwill fire.Edit
I don’t like the look of the bit of sql you are showing:
Not a performance vise good piece of sql code. You can do this instead:
Why use the
distinctthere? When you can just select like above. Back to the question. You can try having theInitialValueset tonamelike this: