How do I get gridview cell value?

Mike Rad 0 Reputation points
2023-04-14T19:06:25.66+00:00

I have a gridview:

<asp:TemplateField HeaderText="First Name">
                                <ItemTemplate>
                                    <asp:Label ID="fNameLbl" Text='<%# Bind("fName") %>' runat="server"></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="fNameTxtBox" Text='<%# Bind("fName") %>' runat="server"></asp:TextBox>
                                    <asp:Label ID="fNameErrorsLbl" CssClass="errorLabels" runat="server"></asp:Label>
                                </EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="editBtn" Text="Edit" CommandName="Edit" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Button ID="updateBtn" Text="Update" CommandName="Update" runat="server" OnClientClick="checkGridView()" />
                                    <asp:Button ID="cancelBtn" Text="Cancel" CommandName="Cancel" runat="server" />
                                </EditItemTemplate>
</asp:TemplateField>


I wanted to do so that when I click the update button to get the value from the cell in the row it was clicked to JS.

I tried this code:

function checkGridView() {

        fNameV = document.getElementById('fNameTxtBox');

        alert(fNameV);
    }

But document.getElementById('fNameTxtBox') returns null. How can I fix it?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
902 questions
0 comments No comments
{count} votes