DataGrid和GridView单击背景变色双击颜色还原
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';";
}
}
摘自 爱智旮旯
上一篇: 词法分析步骤