日期:2014-05-18  浏览次数:20585 次

GridView中怎么判断行被选中?
再用GridView这个控件的时候,我没有用按钮,是鼠标直接点击某行,则这行被选中。所用后台代码:e.Row.Attributes.Add( "OnClick ",   "MouseDownEvent( ' "   +   archiveId   +   " ') ");

然后再前台用javascript:   function   OnClick()来处理鼠标点击事件

但是这里有个问题:因为是在前台的javascript中执行的鼠标点击事件,我后台怎么动态判断鼠标点击的是哪项?(即GridView哪项被选中?)

相关代码:
        protected   void   GridView1_RowDataBound(object   sender,   GridViewRowEventArgs   e)
        {
                identityText.Attributes.Add( "onkeypress ",   "EnterTextBox( 'checkBtnClick ') ");

                string   archiveId   =   null;

                if   (e.Row.RowType   ==   DataControlRowType.DataRow)
                {
                        archiveId   =   e.Row.Cells[1].Text.Trim();

                        e.Row.Attributes[ "style "]   =   "Cursor:hand ";
                        e.Row.Attributes.Add( "OnMouseOut ",   "this.style.backgroundColor= 'White ';this.style.color= '#333333 ' ");
                        e.Row.Attributes.Add( "OnMouseOver ",   "this.style.backgroundColor= '#5D7B9D ';this.style.color= 'Black ' ");
                        e.Row.Attributes.Add( "OnMouseDown ",   "MouseDownEvent( ' "   +   archiveId   +   " ') ");

                }

这个有没有鼠标点击GridView的后台代码??

------解决方案--------------------
1。
说得很是迷糊,搞不定

2。
我后台怎么动态判断鼠标点击的是哪项?
=======
你可以 在 GridView1_RowDataBound 中将 RowIndex 传入脚本函数,后续回发的再提交回来

如,

e.Row.Attributes.Add( "OnMouseDown ", "MouseDownEvent( ' " + archiveId + " ') ");

》》》》

e.Row.Attributes.Add( "OnMouseDown ", String.Format( "MouseDownEvent( '{0} ', {1}) ", archiveId, e.Row.RowIndex));

------解决方案--------------------
你也可以用一个应藏控件来保存一个值,
e.Row.Attributes.Add( "OnClick ", "Click( ' " + e.Row.Cells[1].Text + " ') ");

在调用这个事件时传一个值过去,用应藏控件来保存来保存;
在要取值时取出应藏控件中的值就行了