简体   繁体   English

如何使用Javascript从GridView单元获取价值

[英]How to get value from GridView cell with Javascript

I'm trying to get a value from a GridView cell to change the source of an embed PDF. 我正在尝试从GridView单元中获取一个值,以更改嵌入PDF的来源。 I execute a function when a button that is placed on each row of the GridView is clicked. 单击位于GridView每一行上的按钮时,我将执行一个函数。

This is the code I have so far: 这是我到目前为止的代码:

<script>

    function changepdf(pdf) {

        var value = document.getElementById('<%= GridView1.ClientID %>').rows[pdf.rowIndex].cells[3].innerText;
        var file = document.getElementById('pdf');
        file.src = 'pdf/catalogosh.pdf#page=' + value + '&#toolbar=0&#view=fit';
        return false;
    }

</script>

The Javascript function works fine when I write exactly the new source like this: 当我完全像这样编写新的源代码时,JavaScript函数可以正常工作:

<script>

    function changepdf(pdf) {

        var file = document.getElementById('pdf');
        file.src = 'pdf/catalogosh.pdf#page=4&#toolbar=0&#view=fit';
        return false;
    }

</script>

The main idea is to change the PDF page taking the value from de GridView . 主要思想是使用de GridView的值更改PDF页面。

Thanks in advance for any help. 在此先感谢您的帮助。

I've just solved it. 我已经解决了 I'm pasting the code here for anyone that's trying to solve the same problem: 我在这里将代码粘贴给尝试解决相同问题的任何人:

        function changepdf(pdf) {

        var row = pdf.parentNode.parentNode;
        var rowIndex = row.rowIndex;
        var value = document.getElementById('<%= GridView1.ClientID %>').rows[rowIndex].cells[2].innerText;
        var file = document.getElementById('pdf');
        file.src = 'pdf/catalogosh.pdf#page=' + value + '&#toolbar=0&#view=fit';

        return false;

    }

My problem was the rowIndex . 我的问题是rowIndex The code was bad and I was getting the wrong value. 代码很糟糕,我得到了错误的值。 I added this two lines to get it well: 我添加了以下两行以使其良好:

var row = pdf.parentNode.parentNode;
var rowIndex = row.rowIndex;

And then I got the cell value with this line: 然后我通过这一行获得了单元格值:

var value = document.getElementById('<%= GridView1.ClientID %>').rows[rowIndex].cells[3].innerText;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM