I am encountering significant difficulties with this issue. Despite my extensive search efforts, I am hoping that someone can offer assistance on either explaining the process or demonstrating it to me. Here is the challenge I am facing:
Within an ASP.Net environment, I have a DataGrid populated with DataBound Items using an ItemTemplate approach.
The rationale behind opting for ItemTemplates instead of a conventional DataBound field is to activate the Edit Mode of the DataGrid. Within my ItemTemplates, I have incorporated labels for displaying data and two option buttons (Edit/Delete). The functionality of these buttons has been successfully implemented in the C# code behind.
The Edit button initiates the transition into Edit Mode. In the EditItemTemplates, there are DropdownLists, TextBoxes, and a Save button as replacements for the Edit button.
The Save button also operates effectively based on the designated code. Overall, the DataGrid performs admirably and showcases all content neatly. However, one final task remains - I aim for the Save button to validate the input values within the TextBoxes against predetermined criteria (bear in mind that these elements are located within the EditItemTemplates).
I have already devised Javascript scripts for validation purposes. I intend for a modal window (already configured) to appear and for the CSS styles of relevant TextBoxes to alter accordingly.
My objective is to achieve this through Javascript; however, I am confronted with the issue of not being able to detect the presence of the Save button to trigger the Click event, nor can I seem to identify the target TextBoxes for validation while the DataGrid is in Edit Mode.
If it helps, here is a snippet of the code utilized for assembling the DataGrid:
<asp:DataGrid ID="dgCamsizer" CssClass="data" runat="server" AutoGenerateColumns="False"
GridLines="None" OnItemCommand="dgCamsizer_ItemCommand" ShowHeader="true">
<Columns>
<asp:TemplateColumn HeaderStyle-CssClass="infoHeaderDG">
<HeaderTemplate>
Operator</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Operator" Text='<%# DataBinder.Eval(Container.DataItem, "Operator") %>'
runat="server" /></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EditOper" Width="40px" Text='<%# DataBinder.Eval(Container.DataItem, "Operator") %>'
runat="server"></asp:TextBox></EditItemTemplate>
<HeaderStyle CssClass="infoHeaderDG"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-CssClass="infoHeaderDG">
<ItemTemplate>
<asp:Button ID="Edit" Text="Edit" CommandName="Edit" runat="server" /></ItemTemplate>
<EditItemTemplate>
<asp:Button ID="Save" Text="Save" CommandName="Save" runat="server" /></EditItemTemplate>
<HeaderStyle CssClass="infoHeaderDG"></HeaderStyle>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Perhaps I should rephrase my inquiry: Thanks to Zetlen, I have succeeded in identifying the TextBoxes. Furthermore, I have managed to retrieve the values. Now...how do I proceed to employ those values for validation testing?
Below is the code segment employed to extract the values:
$("#<%=dgCamsizer.ClientID %> :text").each(function () {
alert($(this).val());
});