Search code examples
asp.netinputasp.net-dynamic-data

How do I validate one field based on the data in the another in the same table in my Dynamic Data Website?


I have a table in a my Dynamic Data website that has a Primary Phone Number field and a Country field. I have regular expression for the phone field that validate US domestic phone numbers and International phone numbers. How would I write in my dynamic data application that if a country other than the us is selected in the Country field then the international phone regular expression should be used?

<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
        AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
        RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6" AutoGenerateColumns="false" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" AutoGenerateDeleteButton="true">
        <Columns>                    
            <%--<asp:TemplateField>
                <ItemTemplate>
                    <asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit"
                    />&nbsp;<asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
                        OnClientClick='return confirm("Are you sure you want to delete this item?");'
                    />&nbsp;<asp:DynamicHyperLink runat="server" Text="Details" />
                </ItemTemplate>
            </asp:TemplateField>--%>

            <asp:DynamicField DataField="CA_AgencyName" HeaderText="Agency Name" />
            <asp:DynamicField DataField="CA_AgencyAcronym" HeaderText="Official Acronym"/>
            <asp:DynamicField DataField="CA_AgencyAcronym_SOLID" HeaderText="SOLID Acronym"/>
            <asp:DynamicField DataField="CA_AgencyHomePageURL" UIHint="Url" HeaderText="Web Address"/>
            <asp:DynamicField DataField="CA_AgencyContact" HeaderText="Email/Contact Page"/>
            <asp:DynamicField DataField="CA_AgencyCredentialType" HeaderText="Credential Type"/>
            <asp:DynamicField DataField="CA_AgencyStreetAddress1" HeaderText="Address"/>
            <asp:DynamicField DataField="CA_AgencyStreetAddress2" HeaderText="Address Cont."/>
            <asp:DynamicField DataField="CA_AgencyCity" HeaderText="City"/>
            <asp:DynamicField DataField="CA_AgencyState" HeaderText="State"/>
            <asp:DynamicField DataField="CA_AgencyZip" HeaderText="Zip"/>
            <asp:DynamicField DataField="CA_AgencyCountry" HeaderText="Country" />
            <asp:DynamicField DataField="CA_AgencyPhonePrimary" HeaderText="Primary Phone"/>
            <asp:DynamicField DataField="CA_AgencyPhonePrimaryExtension" HeaderText="Primary Extension"/>
            <asp:DynamicField DataField="CA_AgencyPhoneSecondary" HeaderText="Secondary Phone"/>
            <asp:DynamicField DataField="CA_AgencyRecordAddedUserID" HeaderText="Added By"/>
            <asp:DynamicField DataField="CA_AgencyRecordUpdatedDate" HeaderText="Date Changed"/>
            <asp:DynamicField DataField="CA_AgencyRecordUpdatedUserID" HeaderText="Changed By"/>
            <asp:DynamicField DataField="DOL_ORG_ID" HeaderText="DOL ORG ID"/>
        </Columns>

        <PagerStyle CssClass="DDFooter"/>        
        <PagerTemplate>
            <asp:GridViewPager runat="server" />
        </PagerTemplate>
        <EmptyDataTemplate>
            There are currently no items in this table.
        </EmptyDataTemplate>
    </asp:GridView>

Solution

  • It sounds like what you need is a CompareValidator:

    <asp:CompareValidator ID="CompareValidator1" runat="server" 
        ControlToValidate="MyControl1" 
        ControlToCompare="MyControl2" 
        Operator="GreaterThanEqual" 
        Type="Integer">
    </asp:CompareValidator>