asp.net gridview指定某一列滚动
程序员文章站
2024-03-08 17:21:46
//基本代码设计
//基本代码设计
<div id="div-datagrid">
<asp:datagrid id="datagrid1" runat="server" cssclass="grid" useaccessibleheader="true">
<alternatingitemstyle cssclass="gridaltrow"></alternatingitemstyle>
<itemstyle cssclass="gridrow"></itemstyle>
<columns>
<asp:boundcolumn datafield="name" headertext="name"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="address" headertext="address"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="city" headertext="city"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="state" headertext="state"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="zip" headertext="zip"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="random babble"
headertext="random babble"
itemstyle-wrap="false"></asp:boundcolumn>
</columns>
</asp:datagrid>
</div>
//可以给一个按钮触发lockcol('');
function lockcol(tblid) {
var table = document.getelementbyid(tblid);
var button = document.getelementbyid('toggle');
var ctr = table.getelementsbytagname('tr'); //collection of rows
if (table.rows[0].cells[0].classname == '') {
for (i = 0; i < ctr.length; i++)
{
var tr = ctr.item(i);
tr.cells[0].classname = 'locked'
}
button.innertext = "unlock first column";
} else {
for (i = 0; i < ctr.length; i++)
{
var tr = ctr.item(i);
tr.cells[0].classname = ''
}
button.innertext = "lock first column";
}
}
//css样式代码
/* div container to wrap the datagrid */
div#div-datagrid {
width: 420px;
height: 200px;
overflow: auto;
scrollbar-base-color:#ffeaff;
}
/* locks the left column */
td.locked, th.locked {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*ie5+ only*/
left: expression(document.getelementbyid("div-datagrid").scrollleft-2);
}
/* locks table header 这里是表头不动,要表头动那就把这一段注释!*/
th {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*ie5+ only*/
top: expression(document.getelementbyid("div-datagrid").scrolltop-2);
z-index: 10;
}
/* keeps the header as the top most item. important for top left item*/
th.locked {z-index: 99;}
/* datagrid item and alternatingitem style*/
.gridrow {font-size: 10pt; color: black; font-family: arial;
background-color:#ffffff; height:35px;}
.gridaltrow {font-size: 10pt; color: black; font-family: arial;
background-color:#eeeeee; height:35px;}
///指定那些不动!
sub item_bound(byval sender as object, byval e as datagriditemeventargs) _
handles datagrid1.itemdatabound
e.item.cells(0).cssclass = "locked"
//e.item.cells(1).cssclass = "locked"
end sub
<div id="div-datagrid">
<asp:datagrid id="datagrid1" runat="server" cssclass="grid" useaccessibleheader="true">
<alternatingitemstyle cssclass="gridaltrow"></alternatingitemstyle>
<itemstyle cssclass="gridrow"></itemstyle>
<columns>
<asp:boundcolumn datafield="name" headertext="name"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="address" headertext="address"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="city" headertext="city"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="state" headertext="state"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="zip" headertext="zip"
itemstyle-wrap="false"></asp:boundcolumn>
<asp:boundcolumn datafield="random babble"
headertext="random babble"
itemstyle-wrap="false"></asp:boundcolumn>
</columns>
</asp:datagrid>
</div>
//可以给一个按钮触发lockcol('');
function lockcol(tblid) {
var table = document.getelementbyid(tblid);
var button = document.getelementbyid('toggle');
var ctr = table.getelementsbytagname('tr'); //collection of rows
if (table.rows[0].cells[0].classname == '') {
for (i = 0; i < ctr.length; i++)
{
var tr = ctr.item(i);
tr.cells[0].classname = 'locked'
}
button.innertext = "unlock first column";
} else {
for (i = 0; i < ctr.length; i++)
{
var tr = ctr.item(i);
tr.cells[0].classname = ''
}
button.innertext = "lock first column";
}
}
//css样式代码
/* div container to wrap the datagrid */
div#div-datagrid {
width: 420px;
height: 200px;
overflow: auto;
scrollbar-base-color:#ffeaff;
}
/* locks the left column */
td.locked, th.locked {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*ie5+ only*/
left: expression(document.getelementbyid("div-datagrid").scrollleft-2);
}
/* locks table header 这里是表头不动,要表头动那就把这一段注释!*/
th {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*ie5+ only*/
top: expression(document.getelementbyid("div-datagrid").scrolltop-2);
z-index: 10;
}
/* keeps the header as the top most item. important for top left item*/
th.locked {z-index: 99;}
/* datagrid item and alternatingitem style*/
.gridrow {font-size: 10pt; color: black; font-family: arial;
background-color:#ffffff; height:35px;}
.gridaltrow {font-size: 10pt; color: black; font-family: arial;
background-color:#eeeeee; height:35px;}
///指定那些不动!
sub item_bound(byval sender as object, byval e as datagriditemeventargs) _
handles datagrid1.itemdatabound
e.item.cells(0).cssclass = "locked"
//e.item.cells(1).cssclass = "locked"
end sub
上一篇: 深入浅析Java 循环中标签的作用
下一篇: 解析Java编程中对于包结构的命名和访问
推荐阅读
-
asp.net gridview指定某一列滚动
-
asp.net GridView控件中模板列CheckBox全选、反选、取消
-
asp.net Gridview数据列中实现鼠标悬浮变色
-
asp.net GridView模板列中实现选择行功能
-
asp.net 扩展GridView 增加单选按钮列的代码
-
asp.net Gridview数据列中实现鼠标悬浮变色
-
asp.net GridView模板列中实现选择行功能
-
asp.net中GridView和DataGrid相同列合并实现代码
-
asp.net中GridView和DataGrid相同列合并实现代码
-
asp.net如何得到GRIDVIEW中某行某列值的方法