一、首先引用 JavaScript 和 CSS 文件:
二、添加自定义的 CSS 样式:
class="cnblogs_code_copy">
.gridcell{padding:5px;}.fakeContainer{float:left;margin:5px;border:solid 1px #ccc;width:630px;height:250px;background-color:#ffffff;overflow:hidden;}
三、添加 GridView 网格控件并进行相关设置(包括:后台的数据绑定 和 前台的显示配置)
四、在 GridView 网格控件的下面添加 JavaScript 控制代码:
//
if(grid != null && grid != undefined){
grid.parentNode.className = "fakeContainer";
(var start = new Date();
superTable("grid_Report", {
cssSkin : "Default",
fixedCols : 1,
onFinish : function ()
{
//Basic row selecting for a superTable with/without fixed columns if (this.fixedCols == 0)
{
for (var i=0, j=this.sDataTable.tBodies[0].rows.length; i
{
this.sDataTable.tBodies[0].rows[i].onclick = function (i)
{
var clicked = false;
var dataRow = this.sDataTable.tBodies[0].rows[i];
return function ()
{
if (clicked)
{
dataRow.style.backgroundColor = "#ffffff";
clicked = false;
}
else
{
dataRow.style.backgroundColor = "#eeeeee";
clicked = true;
}
}
}.call(this, i);
}
}
else
{
for (var i=0, j=this.sDataTable.tBodies[0].rows.length; i
{
//xugang begin if(i % 2 == 0){
this.sDataTable.tBodies[0].rows[i].style.backgroundColor = "#f5ffef";
}
if(i >=(j - 2)){
this.sDataTable.tBodies[0].rows[i].style.backgroundColor ="#eeeeee";//"#ffffd2"; }
//xugang end
this.sDataTable.tBodies[0].rows[i].onclick = this.sFDataTable.tBodies[0].rows[i].onclick = function (i)
{
var clicked = false;
var dataRow = this.sDataTable.tBodies[0].rows[i];
var fixedRow = this.sFDataTable.tBodies[0].rows[i];
//var dataRow_old_Color = dataRow.style.backgroundColor; //var fixedRow_old_Color = fixedRow.style.backgroundColor; return function ()
{
if (clicked)
{
//dataRow.style.backgroundColor = fixedRow_old_Color;//"#ffffff"; //fixedRow.style.backgroundColor = fixedRow_old_Color;//"#eeeeee"; clicked = false;
}
else
{
//dataRow.style.backgroundColor = "#ffffd2"; //fixedRow.style.backgroundColor = "#adadad"; clicked = true;
}
}
}.call(this, i);
}
}
return this;
}
});
})();
}
//]]>
注意:此JavaScript 控制代码必须获得GridView 网格控件,所以必须写在GridView 网格控件之后。
效果如下:
全部代码如下
Default.aspx:
View Code
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
无标题页.gridcell{padding:5px;}.fakeContainer{float:left;margin:5px;border:solid 1px #ccc;width:630px;height:250px;background-color:#ffffff;overflow:hidden;}
//
grid.parentNode.className="fakeContainer";
(function() {varstart=newDate();
superTable("grid_Report", {
cssSkin :"Default",
fixedCols :1,
onFinish :function()
{//Basic row selecting for a superTable with/without fixed columnsif(this.fixedCols==0)
{for(vari=0, j=this.sDataTable.tBodies[0].rows.length; i
{this.sDataTable.tBodies[0].rows[i].οnclick=function(i)
{varclicked=false;vardataRow=this.sDataTable.tBodies[0].rows[i];returnfunction()
{if(clicked)
{
dataRow.style.backgroundColor="#ffffff";
clicked=false;
}else{
dataRow.style.backgroundColor="#eeeeee";
clicked=true;
}
}
}.call(this, i);
}
}else{for(vari=0, j=this.sDataTable.tBodies[0].rows.length; i
{//xugang beginif(i%2==0){this.sDataTable.tBodies[0].rows[i].style.backgroundColor="#f5ffef";
}if(i>=(j-2)){this.sDataTable.tBodies[0].rows[i].style.backgroundColor="#eeeeee";//"#ffffd2";}//xugang endthis.sDataTable.tBodies[0].rows[i].οnclick=this.sFDataTable.tBodies[0].rows[i].οnclick=function(i)
{varclicked=false;vardataRow=this.sDataTable.tBodies[0].rows[i];varfixedRow=this.sFDataTable.tBodies[0].rows[i];//var dataRow_old_Color = dataRow.style.backgroundColor;//var fixedRow_old_Color = fixedRow.style.backgroundColor;returnfunction()
{if(clicked)
{//dataRow.style.backgroundColor = fixedRow_old_Color;//"#ffffff";//fixedRow.style.backgroundColor = fixedRow_old_Color;//"#eeeeee";clicked=false;
}else{//dataRow.style.backgroundColor = "#ffffd2";//fixedRow.style.backgroundColor = "#adadad";clicked=true;
}
}
}.call(this, i);
}
}returnthis;
}
});
})();
}//]]>