GridView单击行

1.使用GridView提示选择到的行,可选择多行

问题? 怎么样才能单击此行,其它的以前选择行取消选择状态呢。

步骤1.给GridView的创建RowCreated事件。具体代码如下:  protected void gv_typelist_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        { 
          e.Row.Attributes.Add("id", "row" + e.Row.RowIndex);
        e.Row.Attributes.Add("onclick", "ChangeRowColor('row"+e.Row.RowIndex+"')");
        }
    }

在.aspx页面写入JS:代码如下:<script language ="javascript" type="text/javascript">
var oldColor = '';
function ChangeRowColor(rowID)
{  
var color=document.getElementById(rowID).style.color;
  if(color!='buttontext') 
  oldColor="buttontext";
  if(color=='buttontext')
  document.getElementById(rowID).style.color='' ;
  else
  document.getElementById(rowID).style.color='buttontext' ;
}

</script>

 

 

posted @ 2008-12-10 12:02  飘逸的程序员  阅读(955)  评论(4编辑  收藏  举报