asp.net gridview指定某一列滾動

來源:互聯網
上載者:User

//基本代碼設計
<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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.