0

I've looked at the other post regarding the Same Question

But this is insufficient for what I have to ask about.

It's very simple actually, I want to access the cell value from Javascript.

I have tried this:

var grid = document.getElementById('<%=gvUdgivelser.ClientID%>');
var cell = grid.rows[0].cells[5].innerText;

But I get a undefined in return. If I use the innerHTML I get a result with the full HTML, which I am not interested in.

However, how do I pass a rowIndex to a function from the gridview button, in order for the code to find out which row was clicked?

1
  • Is the button inside of every GridView row? Then you could pass a reference to the js-function from the button's client click handler. Commented Sep 20, 2011 at 14:03

2 Answers 2

3

try this :

var grid = document.getElementById('<%=gvUdgivelser.ClientID%>');
var cell = grid.rows[0].cells[5].textcontent;

hope this help

Sign up to request clarification or add additional context in comments.

Comments

0

If you don't mind using JQuery, you can retrieve the cells value like so:

var rowIndex = 1;
var cellIndex = 5;
var cellValue = $('#<%= gvUdgivelser.ClientID %> tbody tr:eq(' + rowIndex + ') td:eq(' + cellIndex + ')').html();

As for determining the row index, you can do this by creating a button within the grid view:

<asp:TemplateField>
    <ItemTemplate>
        <input type="button" onclick="getRowIndex(this);" value="Get Row Index" />
    </ItemTemplate>
</asp:TemplateField>

And then make use of JQuery again to determine the row index:

function getRowIndex(button) {
    var closestRow = $(button).closest('tr');
    var rowIndex = $('tr').index(closestRow);
}

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.