473,383 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

GridView ItemTemplate - Validators not being called

Mel
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>
Oct 31 '08 #1
1 5156
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>
Oct 31 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
0
by: danc | last post by:
I am trying to modify the layout of a row based on the value in some data (I am creating a subtotal line). This works fine when the page is first loaded, but when it's reloaded, the wrong column is...
0
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this...
0
by: Mike P | last post by:
I am trying to edit a gridview while using paging, but whenever I try to edit a row on a page other than page 1, I get an error. Here is my gridview and my code : <asp:GridView ID="GridView1"...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
0
by: ballamber | last post by:
This is a solution to the problem. Works with .NET 2.0. So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls. I...
2
by: CJM | last post by:
I have a page that allows the user to search a DB by querying one of 3 fields. When results are returned, I want the user to be able to click a value in one of three columns (that directly relate...
3
by: RobertTheProgrammer | last post by:
Hi folks, I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. ...
1
nitindel
by: nitindel | last post by:
Hi All, Please tell me any good site for Gridview control.(not for datagrid). I am facing error in fetching the values of the Bound columns in the gridview: lease tell me how should i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.