GridView ItemTemplate - Validators not being called

Discussion in 'ASP .Net' started by Mel, Oct 31, 2008.

  1. Mel

    Mel Guest

    I have a GridView that is bound to a DataTable. I decided to allow
    the user to change the column data right in the ItemTemplate. Then
    user won't need to click Edit to change the values and then click
    Update to save them because for this application the user will need to
    edit the data in every row so I thought the ItemTemplate would be a
    better solution. However, when I place the controls in my
    ItemTemplate my Validators are not being called at all when they enter
    invalid data. Won't the GridView work this way?

    Here is a small snippet of one item template column:
    <asp:TemplateField HeaderText="Duration (days)"
    SortExpression="Duration">
    <EditItemTemplate>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:TextBox ID="txtDuration" runat="server" Text='<%#
    Bind("[Duration]") %>' Width="56px" CausesValidation="True"
    Wrap="False" ValidationGroup="AllValidators"></asp:TextBox><br />
    <asp:RequiredFieldValidator ID="rfvDuration" runat="server"
    ControlToValidate="txtDuration"
    ErrorMessage="Enter a Duration (number of days)."
    SetFocusOnError="True" Display="Dynamic"
    ValidationGroup="AllValidators"></asp:RequiredFieldValidator><br />
    <asp:RangeValidator ID="rvDuration" runat="server"
    ControlToValidate="txtDuration"
    ErrorMessage="Enter a number between 0 and 365 days."
    MaximumValue="365"
    MinimumValue="0" SetFocusOnError="True" Display="Dynamic"
    Type="Integer" ValidationGroup="AllValidators"></asp:RangeValidator>
    </ItemTemplate>
    <ItemStyle VerticalAlign="Top" />
    </asp:TemplateField>
    Mel, Oct 31, 2008
    #1
    1. Advertising

  2. Mel

    bruce barker Guest

    the control triggering the postback has to have causes validation set to
    true, and have the validation group set to match your specification.

    -- bruce (sqlwork.com)


    "Mel" wrote:

    > I have a GridView that is bound to a DataTable. I decided to allow
    > the user to change the column data right in the ItemTemplate. Then
    > user won't need to click Edit to change the values and then click
    > Update to save them because for this application the user will need to
    > edit the data in every row so I thought the ItemTemplate would be a
    > better solution. However, when I place the controls in my
    > ItemTemplate my Validators are not being called at all when they enter
    > invalid data. Won't the GridView work this way?
    >
    > Here is a small snippet of one item template column:
    > <asp:TemplateField HeaderText="Duration (days)"
    > SortExpression="Duration">
    > <EditItemTemplate>
    > </EditItemTemplate>
    > <ItemTemplate>
    > <asp:TextBox ID="txtDuration" runat="server" Text='<%#
    > Bind("[Duration]") %>' Width="56px" CausesValidation="True"
    > Wrap="False" ValidationGroup="AllValidators"></asp:TextBox><br />
    > <asp:RequiredFieldValidator ID="rfvDuration" runat="server"
    > ControlToValidate="txtDuration"
    > ErrorMessage="Enter a Duration (number of days)."
    > SetFocusOnError="True" Display="Dynamic"
    > ValidationGroup="AllValidators"></asp:RequiredFieldValidator><br />
    > <asp:RangeValidator ID="rvDuration" runat="server"
    > ControlToValidate="txtDuration"
    > ErrorMessage="Enter a number between 0 and 365 days."
    > MaximumValue="365"
    > MinimumValue="0" SetFocusOnError="True" Display="Dynamic"
    > Type="Integer" ValidationGroup="AllValidators"></asp:RangeValidator>
    > </ItemTemplate>
    > <ItemStyle VerticalAlign="Top" />
    > </asp:TemplateField>
    >
    bruce barker, Oct 31, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    657
    Ratman
    Sep 14, 2004
  2. Bennett Haselton
    Replies:
    1
    Views:
    5,332
    Joe Fallon
    Sep 24, 2004
  3. Keithb
    Replies:
    0
    Views:
    2,897
    Keithb
    Nov 4, 2006
  4. Stephan Steiner

    varchar string not showing up in itemtemplate in a gridview

    Stephan Steiner, May 7, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    716
    Stephan Steiner
    May 7, 2007
  5. Felix
    Replies:
    1
    Views:
    337
    Felix
    Sep 29, 2006
Loading...

Share This Page