当前位置: 移动技术网 > IT编程>开发语言>.net > DataGrid和GridView单击背景变色双击颜色还原

DataGrid和GridView单击背景变色双击颜色还原

2018年12月07日  | 移动技术网IT编程  | 我要评论

国债利率表2012,陈云子女,九游战歌网

datagrid中

首先我们假设.x文件中datagrid的数据行的样式为

        <alternatingitemstyle backcolor="white" forecolor="#284775" />
        <itemstyle backcolor="#f7f6f3" forecolor="#333333" />则在datagrid的itemdatabound事件中添加如下代码即可


        if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
        {
               e.item.attributes["onclick"] = "javascript:c=this.style.backgroundcolor;this.style.background='#ffa500';";  //current 粉蓝色 //--#6699ff 蓝色 #ffff00 黄色 #ffffe0 亮黄色
            if (e.item.itemtype == listitemtype.item)
            {
                e.item.attributes["ondblclick"] = "javascript:this.style.background='#f7f6f3';";
            }
            else
            {
                e.item.attributes["ondblclick"] = "javascript:this.style.background='#ffffff';";
            }  
        }
gridview中

首先我们假设.aspx文件中gridview的数据行的样式为

   <alternatingrowstyle backcolor="white" forecolor="#284775" />
   <rowstyle backcolor="#f7f6f3" forecolor="#333333"/>则在gridview的rowdatabound事件中添加如下代码即可


        if (e.row.rowtype == datacontrolrowtype.datarow)
        {

            e.row.attributes["onclick"] = "javascript:c=this.style.backgroundcolor;this.style.background='#ffa500';";

            if (e.row.rowstate == datacontrolrowstate.normal)
            {
                e.row.attributes["ondblclick"] = "javascript:this.style.background='#f7f6f3';";
            }

            if (e.row.rowstate == datacontrolrowstate.alternate)
            {
                e.row.attributes["ondblclick"] = "javascript:this.style.background='white';";
            }

        }

 

 

摘自 爱智旮旯

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网