JavaScript从网格中检索值

JavaScript从网格中检索值,javascript,Javascript,我有一个RowDataBound事件,如下所示 protected void GridLedger_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onMouseDown", "var str = document.getElementById('" + e.

我有一个
RowDataBound
事件,如下所示

protected void GridLedger_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) 
    {
        e.Row.Attributes.Add("onMouseDown", "var str = document.getElementById('" + e.Row.ClientID + "').cells[0].innerText; document.getElementById('<%=TextBox1.ClientID%>').value = str;");
    } 
}
受保护的无效GridLedger\u行数据绑定(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
e、 行.Attributes.Add(“onMouseDown”,“var str=document.getElementById(“+e.Row.ClientID+”))。单元格[0]。innerText;document.getElementById(“)。value=str;”;
} 
}
触发此事件时,我收到以下错误:

未找到对象元素或不是对象


为什么会出现这个错误?

我建议您使用jQuery库或任何其他javascript框架,以使您的生活更加轻松

在我看来,这个错误可能是找不到要查找的对象,或者属性单元格不存在。这甚至可能因浏览器而异


看看你生成的代码,看看错误的ID是什么

海。请花点时间写一些合适的句子,好吗?