Javascript运行时错误:无法设置未定义或空引用的属性“classname” [英] Javascript runtime error: unable to set property 'classname' of undefined or null reference

查看:922
本文介绍了Javascript运行时错误:无法设置未定义或空引用的属性“classname”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unable to set property 'className' of undefined or null reference.

When i click the selected row in a grid i am getting the following error. It should fire gridview_selectedIndexChanged() event. but it will not fire anything. rather than it will shoe the below error.

Error : JavaScript runtime error: Unable to set property 'className' of undefined or null reference.

Error code :

ASPX Page

  var gridviewID = "<%=grdSearch.ClientID%>";         var gridview = null;

        var selectedRowIndex = -1;

        $(document).ready(function () {             gridview = $('#' + gridviewID);

        });

        function RowMouseOver(rowIndex) {             if (selectedRowIndex == rowIndex) return;

            var gridviewID = "<%=grdSearch.ClientID%>";             $('#' + gridviewID)[0].rows[rowIndex + 1].className = 'GridviewScrollItemHover';

        }

        function RowMouseOut(rowIndex) {             if (selectedRowIndex == rowIndex) return;

            var gridviewID = "<%=grdSearch.ClientID%>";             $('#' + gridviewID)[0].rows[rowIndex + 1].className = 'GridviewScrollItem';

        }

        function RowSelect(rowIndex) {             if (selectedRowIndex == rowIndex) return;

            RowReset(selectedRowIndex);

            selectedRowIndex = rowIndex;

            var gridviewID = "<%=grdSearch.ClientID%>";             $('#' + gridviewID)[0].rows[rowIndex + 1].className = 'GridviewScrollItemSelected';

        }

        function RowReset(rowIndex) {

            var gridviewID = "<%=grdSearch.ClientID%>";             $('#' + gridviewID)[0].rows[rowIndex + 1].className = 'GridviewScrollItem';

        }

ASPX.Vb

 

If e.Row.RowType = DataControlRowType.DataRow Then

               

If e.Row.RowType <> DataControlRowType.DataRow Then

                   

Return

               

End If

                e.Row.Attributes(

"onmouseover") = String.Format("RowMouseOver({0});", e.Row.RowIndex)

                e.Row.Attributes.Add(

"style", "cursor:pointer;")

                e.Row.Attributes(

"onmouseout") = String.Format("RowMouseOut({0});", e.Row.RowIndex)

                e.Row.ToolTip =

"Click to select row"

                e.Row.Attributes(

"onclick") = String.Format("RowSelect({0});", e.Row.RowIndex)

           

End If


my Requirment is :

When i selecte the particular row, it should highlight the row in diff color at the same time the index value should get display in another gridview

pls. help me to solve this problem. i am unable to find out exact solution for this.





我尝试了什么:



函数RowReset(rowIndex){

$('#'+ gridviewID +'tbody> tr')。eq(rowindex + 1).addClass ('GridviewScrollItem');

}



但是,不工作......



What I have tried:

function RowReset(rowIndex) {
$('#' + gridviewID +'tbody > tr').eq(rowindex+1).addClass('GridviewScrollItem');
}

But, not working...

推荐答案

(document).ready(function(){gridview =
(document).ready(function () { gridview =


('#'+ gridviewID);

});

函数RowMouseOver(rowIndex){if(selectedRowIndex == rowIndex)return;

var gridviewID =<%= grdSearch.ClientID%>;
('#' + gridviewID); }); function RowMouseOver(rowIndex) { if (selectedRowIndex == rowIndex) return; var gridviewID = "<%=grdSearch.ClientID%>";


('#'+ gridviewID)[0] .rows [rowIndex + 1] .className ='GridviewScrollItemHover';

}

函数RowMouseOut(rowIndex){if(selectedRowIndex == rowIndex)return;

var gridviewID =<%= grdSearch.ClientID%>;
('#' + gridviewID)[0].rows[rowIndex + 1].className = 'GridviewScrollItemHover'; } function RowMouseOut(rowIndex) { if (selectedRowIndex == rowIndex) return; var gridviewID = "<%=grdSearch.ClientID%>";


这篇关于Javascript运行时错误:无法设置未定义或空引用的属性“classname”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆