How to get Column Value for a given Row within GridView using javascript in asp.net?
37,021
Solution 1
Check this out...
var tbl = document.getElementById('Gridview1');
var tbl_row = tbl.rows[parseInt(RowIndex) + 1];
var tbl_Cell = tbl_row.cells[no of the cell];
var value= tbl_Cell.innerHTML.toString();
Here no of the cell
indicates the column number.
If it is a template field,you can try this..
var value=document.getElementById('GridViewId_ColumnID_' + RowIndex).value;
Solution 2
A simple example.
function myfunc {
var b=document.getElementById("GridView1");
var c=document.getElementById("TextBox1");
var d=document.getElementById("TextBox2");
dd=dd+1;
c.value=document.getElementById("GridView1").rows[dd].cells[2].innerHTML;
d.value=document.getElementById("GridView1").rows[dd].cells[3].innerHTML;
}
Get the id of the grid. Then you play around it by using rows[]
and cells[]
Author by
user3264676
Updated on July 28, 2020Comments
-
user3264676 almost 4 years
I have a GridView, I have a row index in a javascript function. Now I want to get the value of a Column for that index in a GridView using javascript. Please tell me how can I do this?
-
Adil about 10 yearsPlease show us the generated html in relation to you question.
-
-
user3264676 about 10 yearsIts working fine. But I want to get the value at this variable value in your code. How to do this.
-
Jameem about 10 yearsThe variable 'value' has the value of the paricular cell..Is it a template feild?
-
user3264676 about 10 yearsyes template field. alert(value); is coming. <span id="GridViewId_ColumnID_0">Pending</span> I want to get the value at this id , in my case its Pending.
-
user3264676 about 10 yearsalert(value); is coming undefined :(
-
Jameem about 10 yearsI have edited the answer..var value=document.getElementById('GridViewId_ColumnID_' + RowIndex).value;
-
user3264676 about 10 yearsyes, I have tried that too. var value = document.getElementById('GridViewMultiplePOSAssociationId_LabelStatusPendingPOSId_0').value; alert(value);
-
Jameem about 10 yearsIs it a label..?var value = document.getElementById('GridViewMultiplePOSAssociationId_LabelStatusPendingPOSId_0').innerHTML; alert(value);