我用的js方法冻结表头,如果电脑屏幕太小,像14寸的本,就会出现这样的问题。为了好看,每列的列宽都是我自己定义的,而且明显超过了100%,js代码如下,在后台用这句调用即可 : ScriptManager.RegisterClientScriptBlock(Me, GetType(UpdatePanel), "", "jQuery(function(){jQuery.fn.CloneTableHeader('GridView1', 'divContent'); }); ", True)
有空的研究一下。
1 jQuery.fn.CloneTableHeader = function() { 2 var _obj_tbHead = document.getElementById('GridView1'); 3 if (_obj_tbHead != null && _obj_tbHead.rows.length > 1) { 4 for (var i = 0; i < _obj_tbHead.rows[0].cells.length; i++) { 5 _obj_tbHead.rows[1].cells[i].style.cssText = _obj_tbHead.rows[0].cells[i].style.cssText; 6 } 7 var _obj_tbBody = _obj_tbHead.cloneNode(true); 8 _obj_tbBody.deleteRow(0); 9 for (i = _obj_tbHead.rows.length - 1; i > 0; i--) { 10 _obj_tbHead.deleteRow(i) 11 } 12 _obj_tbHead.insertAdjacentHTML('afterEnd', '<div id="GridView1_divBody" style="overflow-y:scroll; width:' + _obj_tbHead.style.width + '; height:540px;"></div>'); 13 _obj_tbHead.insertAdjacentHTML('afterEnd', '<div id="GridView1_divHead" style="width:100%;"></div>'); 14 var ver = navigator.appVersion; 15 var browserVersion = parseFloat(ver.substring(ver.indexOf('MSIE') + 5, ver.lastIndexOf('Windows'))); 16 var bvwidth = 16; 17 if (browserVersion == 6.0 || browserVersion == 7.0) { 18 bvwidth = 0; 19 } 20 var wbody = document.getElementById('GridView1_divBody').offsetWidth; 21 document.getElementById('GridView1_divBody').style.width = wbody + bvwidth; 22 var whead = document.getElementById('GridView1_divHead').offsetWidth; 23 document.getElementById('GridView1_divHead').style.width = whead; 24 25 document.getElementById("GridView1_divHead").appendChild(_obj_tbHead); 26 document.getElementById("GridView1_divBody").appendChild(_obj_tbBody); 27 } 28 }