Get first row and first column gridview JavaScript

1

I'm trying to get the value of the first row and first column of the gridview through javascript, however it is returning error. Here's how I'm trying to do it:

var grid = document.getElementById("#<%=GridView12.ClientID %>");
var cell = grid.rows[parseInt(selectedRowIndex) + 1].cells[0];
var hidID = cell.childNodes[0];
document.getElementById('textcodigo').value = hidID;

I get the following error:

  

Uncaught TypeError: Can not read property 'rows' of null

I was able to get to this code:

var grid = document.getElementById("<%=GridView12.ClientID %>");
var cell = grid.rows[0].cells[0];
var hidID = cell.childNodes[0];
document.getElementById('textcodigo').value = hidID;

But in textcode, [object Text] appears. I need the first line, the first column.

This is my GridView12:

<asp:GridView ID="GridView12" runat="server" AutoGenerateColumns="False" DataKeyNames="identificador" CellPadding="4" CssClass="table table-responsive table-hover table-striped" GridLines="None" OnRowDeleting="GridView12_RowDeleting1">
  <Columns>
    <asp:BoundField ItemStyle-Width="100px" DataField="identificador" HeaderText="Identificador" SortExpression="identificador"></asp:BoundField>
    <asp:TemplateField>
      <ItemTemplate>
        <asp:LinkButton CssClass="btn btn-danger btn-sm" ID="deleteButton" runat="server" CommandName="Delete" Text="Excluir" OnClientClick="return confirm('Deseja excluir o identificador selecionado?');"></asp:LinkButton>
      </ItemTemplate>
      <ItemStyle Width="10px" />
    </asp:TemplateField>
  </Columns>
</asp:GridView>

And I got this function, but it keeps coming back to me undefined.

var grid = document.getElementById("<%=GridView12.ClientID %>");
var cellPivot;

if (grid.rows.length > 0) {

  var theDropdown = grid.rows[0].cells[0].text;
  document.getElementById('textcodigo').value = theDropdown;

}
    
asked by anonymous 27.03.2018 / 15:14

0 answers