User1109297939 posted
Hi,
I need some help regarding displaying cell value.
I have a gridview in which I have out onclick event handler in the RowDataBound event.
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", string.Format("DisplayDetails('{0}');", e.Row.RowIndex));
}
}
The DisplayDetails function, I want to run it on the Client Side.
function DisplayDetails(row) {
var gridView = document.getElementById('gridview1');
document.getElementById("textbox1").value = gridView.rows[row + 1].cells[0].innerText ;
document.getElementById("textbox2").value = gridView.rows[row + 1].cells[1].innerText ;
}
The code works if I click on the first row of each Page.
Now when I ever I click on the other Rows, I get errors saying :
JavaScript runtime error: Unable to get property 'innerText' of undefined or null reference
Sometimes I get this too
JavaScript runtime error: Unable to get property 'cells' of undefined or null reference
please help.
P.S Code works if I write
gridView.rows[row ].cells[0].innerText;
instead of
gridView.rows[row + 1].cells[0].innerText;
but it gives the value of the previous row.