Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView ItemTemplate - Validators not being called

Reply
Thread Tools

GridView ItemTemplate - Validators not being called

 
 
Mel
Guest
Posts: n/a
 
      10-31-2008
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>
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      10-31-2008
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>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
varchar string not showing up in itemtemplate in a gridview Stephan Steiner ASP .Net Datagrid Control 0 05-07-2007 12:46 PM
Gridview control will not wrap text in ItemTemplate Labels Keithb ASP .Net 0 11-04-2006 12:28 AM
WebService called by automation dll times out when being called from Navision Felix ASP .Net Web Services 1 09-29-2006 01:43 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM
Regular Expression validators NOT working, Required Field validators ARE working Ratman ASP .Net 0 09-14-2004 09:36 PM



Advertisments