请问如何实现在鼠标移动的时候,鼠标指定的datagrid行变色?

解决方案 »

  1.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
    if(e.Item.ItemIndex!=-1) {
    e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor);this.style.cursor='hand',this.style.backgroundColor='#dddddd'");
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
    }
    }
      

  2.   

    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
    e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#738A9C';this.style.cursor='hand'");
    }
    if(e.Item.ItemType==ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7F7F7'"); 
    }
    else if(e.Item.ItemType==ListItemType.Item)
    {e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#E7E7FF'"); };
      

  3.   

    private void dgCatalog_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    ListItemType itemType = e.Item.ItemType;
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
    if (itemType == ListItemType.Item )
    {
    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
    }
    else if( itemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
    }
      

  4.   

    我应该怎么来触发这个事件呢:private void dataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)?我在aspx页面是这样写的:
    <asp:datagrid id="dataGrid1" Width="100%" OnItemDataBound="dataGrid1_ItemDataBound()" Runat="server" AllowSorting="True" AllowPaging="True"
    AutoGenerateColumns="False" ShowHeader="False" CssClass="tr1">这是系统的出错信息:ASP.SelProjectInfo_aspx”并不包含对“dataGrid1_ItemDataBound”的定义
      

  5.   

    superryy你代码我用了,很好,可是唯一有点麻烦的是,你没对datagrid里的一行做处理,我不知道你的datagrid里的数据才用何种方法绑定的,但应该用程序判断一下从第2行开始变颜色,第一行是标题,颜色应该不变才对。但是很很感谢你的代码,我正想实现这个功能呢,就找到了你的留言,很感谢。
      

  6.   

    触发这个事件的方法,你点datatgarid的属性,你在属性里可以看到个黄色的小闪电标志,打开它,里边有各种时间,找出ItemDataBound,然后双点,就将自动进入后台就可以写superryy的代码了,但他没对第一行进行判断,所以第一行做为标题也参与变色,这需要完善。