Click here to Skip to main content
16,016,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI to All
This is My HTML Code Bust Not Work Correctly
When Run Program And Click Insert show message Please Enter Discipline
Please Help Me.

XML
<asp:TemplateField HeaderText="Discipline">
    <EditItemTemplate>
        <asp:DropDownList ID="lstDiscipline" runat="server" Text='<%# Bind("Discipline") %>'>
            <asp:ListItem Text="AR" Value="AR"></asp:ListItem>
            <asp:ListItem Text="PI" Value="PI"></asp:ListItem>
            <asp:ListItem Text="ST" Value="ST"></asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="rfvDiscipline" ValidationGroup="Update" runat="server"
            ControlToValidate="lstDiscipline" ErrorMessage="Please Enter Discipline" InitialValue="-1"
            ToolTip="Please Enter Discipline" SetFocusOnError="true" ForeColor="Red">*
        </asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="reDiscipline" runat="server" ControlToValidate="lstDiscipline"
            ErrorMessage="Please Enter Discipline" ToolTip="Please Enter Discipline" InitialValue="-1"
            SetFocusOnError="true" ForeColor="Red" ValidationExpression="\*" ValidationGroup="Update">*
        </asp:RegularExpressionValidator>
    </EditItemTemplate>
    <FooterTemplate>
        <asp:DropDownList ID="lstDiscipline" runat="server" >
            <asp:ListItem Text="AR" Value="AR"></asp:ListItem>
            <asp:ListItem Text="PI" Value="PI"></asp:ListItem>
            <asp:ListItem Text="ST" Value="ST"></asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="rfvDiscipline" ValidationGroup="Insert" runat="server"
            ControlToValidate="lstDiscipline" ErrorMessage="Please Enter Discipline" InitialValue="-1"
            ToolTip="Please Enter Discipline" SetFocusOnError="true" ForeColor="Red">*
        </asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="reDiscipline" runat="server" ControlToValidate="lstDiscipline"
            ErrorMessage="Please Enter Discipline" ToolTip="Please Enter Discipline" InitialValue="-1"
            SetFocusOnError="true" ForeColor="Red" ValidationExpression="\*" ValidationGroup="Insert">*
        </asp:RegularExpressionValidator>
    </FooterTemplate>
    <ItemTemplate>
        <%# Eval("Discipline")%>
    </ItemTemplate>
</asp:TemplateField>
Posted
Updated 27-Mar-14 21:52pm
v2

1 solution

See -1 is a concept about dropdown item index.
InitialValue concept: will check the selected item value if it will match with initialValue the required field validation will catch.

For that you have assign one select item to each of dropdownlist
Like below
ASP.NET
<asp:DropDownList ID="lstDiscipline" runat="server" >   
<asp:ListItem Text="Select" Value="-1"></asp:ListItem>        
  <asp:ListItem Text="AR" Value="AR"></asp:ListItem>
          <asp:ListItem Text="PI" Value="PI"></asp:ListItem>
          <asp:ListItem Text="ST" Value="ST"></asp:ListItem>
      </asp:DropDownList>
      <asp:RequiredFieldValidator ID="rfvDiscipline" ValidationGroup="Insert" runat="server"
          ControlToValidate="lstDiscipline" ErrorMessage="Please Enter Discipline" InitialValue="-1"
          ToolTip="Please Enter Discipline" SetFocusOnError="true" ForeColor="Red">*
      </asp:RequiredFieldValidator>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900