How To Control Which Validators Are Used In A DataGrid
I'm developing a web page in Asp.Net 1.1 and have a DataGrid which allows users to add, edit, and delete database records. The footer row contains textboxes to allow the adding of new records.
For each column I've defined <ItemTemplate>, <EditItemTemplate> and <FooterItemTemplate> elements. The FooterItemTemplate and EditItemTemplate elements in my aspx markup both contain RequiredFieldValidator controls as well as text boxes. (see below)
<asp:TemplateColumn HeaderText="Offer Code">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.OfferCode") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewOfferCode" Runat="server" />
<asp:RequiredFieldValidator ID="reqNewOfferCode" ControlToValidate="txtNewOfferCode" Display="None" ErrorMessage="Please specify 'Offer Code'" Runat="server" />
</FooterTemplate>
<EditItemTemplate>
<asp:TextBox id=txtOfferCode Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OfferCode") %>' />
<asp:RequiredFieldValidator ID="reqOfferCode" ControlToValidate="txtOfferCode" Display="None" ErrorMessage="Please specify 'Offer Code'" Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
The problem I have is that when you try to edit an existing record, the blank fields in the footer row prevent validation and hence postback and updating of the selected row.
Answer
Normally, the GridView is not able to insert new rows. You did the trick, using the footer row. Of course, when you submit your GridView, the validators block the process because the field are empty. You should trap the event when your GridView goes in edit mode and disable the footer's validators. Don't forget to enable them when you leave the GridView edit mode.
Related Questions
- → Function Undefined in Axios promise
- → React formatting dates with momentjs server side
- → Using ReactJs, How do I update my form fields when my parent object sent in from props changes?
- → Visual Studio 2012 Express: Browser returning 500 status trying to download jsx file
- → AngularJS directive: "templateUrl" doesn't work while "template" works
- → how to add cannonical tag for ASPX .NET page
- → Javascript Paypal slider string suffix
- → JavaScript in MVC 5 not being read?
- → Selecting an element by its attribute when it has a colon in its name
- → Function works for NON dynamically loaded images
- → URL routing requires /Home/Page?page=1 instead of /Home/Page/1
- → There are "gaps" between rows in my masonry cards
- → creating sef links and changing plus sign (+) with dash (-)