android gridview 表头,固定GridView 的表头和某几列

一、首先引用 JavaScript 和 CSS 文件:

二、添加自定义的 CSS 样式:

class="cnblogs_code_copy">

5ef1641c1443bc713df625d839515760.gif

.gridcell{padding:5px;}.fakeContainer{float:left;margin:5px;border:solid 1px #ccc;width:630px;height:250px;background-color:#ffffff;overflow:hidden;}

5ef1641c1443bc713df625d839515760.gif

三、添加 GridView 网格控件并进行相关设置(包括:后台的数据绑定 和 前台的显示配置)

5ef1641c1443bc713df625d839515760.gif

5ef1641c1443bc713df625d839515760.gif

四、在 GridView 网格控件的下面添加 JavaScript 控制代码:

5ef1641c1443bc713df625d839515760.gif

//

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;

}

});

})();

}

//]]>

5ef1641c1443bc713df625d839515760.gif

注意:此JavaScript 控制代码必须获得GridView 网格控件,所以必须写在GridView 网格控件之后。

效果如下:

22a3b1749ef9cb4bd0ed02bfb9c3402d.png

全部代码如下

Default.aspx:

833e4bfd64f0f1b81e5f9b52b7311cec.gif

9a4fbd59b10923278342dec71e9531d0.gifView 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;

}

});

})();

}//]]>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值