当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net gridview指定某一列滚动

ASP.NET
ASP.NET动态创建控件之绝境求生
客户端回调实现gridView无刷新分页
ASP.NET2.0中将文件上传到数据库
ASP.NET2.0轻松搞定统计图表
asp.net ajax 使用updatepanel更新后的提示
Asp.Net对Xml文件的操作
Asp.net 远程抓取,分解,保存,匹配
ASP.NET 中处理页面“回退”的方法
ASP.NET 2.0中轻松实现网站换肤
C#+ASP.NET 2.0 定制复合组件之基础篇
C#+ASP.NET 2.0 定制复合组件之高级篇
ASP.NET 2.0 服务器控件之复合控件事件
在Apache上调试ASP.NET 1.1/2.0代码
ASP.NET中的DataGrid的属性
动态的管理ASP.NET DataGrid数据列
ASP.NET网站程序预防SQL注入式攻击策略
Windows下SVN配置和apache的配置
.NET事件处理的过程
ASP.net技术:AJAX实现留言板信息展开
三代IIS下ASP.net请求处理过程

ASP.NET 中的 asp.net gridview指定某一列滚动


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 52 ::
收藏到网摘: n/a

gridview指定某一列滚动的asp.net实现代码。 //基本代码设计
<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