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

datagrid添加单击事件~~~
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
 if(e.Item.ItemIndex>-1)
 {
if(e.Item.ItemIndex<0)
return;
  if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","currentcolor = this.style.backgroundColor;this.style.backgroundColor ='#5A7EBF'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor = currentcolor");
e.Item.Attributes.Add("onfocusout","this.style.backgroundColor='#ffffffffF'");
  }
TableRow tbname = (TableRow)e.Item.Cells[0].Parent;
tbname.Attributes.Add("onclick","javascript:transfer('"+e.Item.Cells[1].Text+"@"+e.Item.Cells[2].Text+"')");
e.Item.Attributes.Add("onclick","currentcolor = this.style.backgroundColor;this.style.backgroundColor = '808080'");
  }
}
我想做的是单击时选择到某行,这一行变色,而且可以在单击的时候取得这行单元格的值,现在两个onclick方法中只会执行一个,即最后定义的onclick事件,有没有什么方法让单击实现变色又取得当前行的值???

------解决方案--------------------
把颜色改变放在JS里实现~
------解决方案--------------------
1 弹出单元格的值

<asp:GridView ID="GridView3" onclick="test()" runat="server" OnRowCreated="GridView3_RowCreated">
</asp:GridView> 

test()代码如下
HTML code
<script type="text/javascript">
    function test()
    {
        var obj=event.srcElement;
        alert(obj.innerText);
    }
    </script>