asp.net gridview指定某一列滾動
更新時間:2009年11月26日 18:59:26 作者:
gridview指定某一列滾動的asp.net實(shí)現(xiàn)代碼。
//基本代碼設(shè)計(jì)
<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>
//可以給一個按鈕觸發(fā)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>
//可以給一個按鈕觸發(fā)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
您可能感興趣的文章:
相關(guān)文章
.NET更新Xml中CDATA內(nèi)容的方法實(shí)例
這篇文章介紹了.NET更新Xml中CDATA內(nèi)容的方法實(shí)例,有需要的朋友可以參考一下2013-07-07
Gridview利用DataFormatString屬性設(shè)置數(shù)據(jù)格式的方法
這篇文章主要介紹了Gridview利用DataFormatString屬性設(shè)置數(shù)據(jù)格式的方法,涉及Gridview屬性操作及數(shù)據(jù)格式相關(guān)技巧,需要的朋友可以參考下2016-03-03
Asp.net SignalR 讓實(shí)時通訊變得如此簡單
下面小編就為大家分享一篇Asp.net SignalR 讓實(shí)時通訊變得如此簡單,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
ASP.NET中實(shí)現(xiàn)獲取調(diào)用方法名
這篇文章主要介紹了ASP.NET中實(shí)現(xiàn)獲取調(diào)用方法名的技巧,較為詳細(xì)的講述了相關(guān)的命名空間的調(diào)用及語句執(zhí)行順序,具有一定的參考借鑒價值,需要的朋友可以參考下2014-12-12
在Global.asax文件里實(shí)現(xiàn)通用防SQL注入漏洞程序(適應(yīng)于post/get請求)
可使用Global.asax中的Application_BeginRequest(object sender, EventArgs e)事件來實(shí)現(xiàn)表單或者URL提交數(shù)據(jù)的獲取,獲取后傳給SQLInjectionHelper類ValidUrlData方法來完成檢查2013-01-01
ASP.NET數(shù)據(jù)綁定之Repeater控件
這篇文章主要介紹了ASP.NET數(shù)據(jù)綁定中的Repeater控件,Repeater控件可以將數(shù)據(jù)庫中的信息加以綁定然后再在瀏覽器中顯示出來,感興趣的小伙伴們可以參考一下2016-01-01
集合類List與Dictonary實(shí)例練習(xí)
本文將詳細(xì)介紹下List<>泛型集合/Dictonary<>字典/泛型集合練習(xí) /中日期轉(zhuǎn)換提取為方法以及泛型集合練習(xí)之翻譯軟件,感興趣的你可不要錯過了哈2013-02-02

