gridivew增加了凍結表頭后,同時增加一個模板列checkbox,如果表格中的資料太多會自動生成垂直滾動條,當滾動條拉向下后將滑鼠指向模板列任一checkbox,凍結表頭會自動消失,需要將滾動條拉到置頂并重新將滑鼠指向任一checkbox,表頭才會重新顯示出來,請問如何解決表頭不要消失,代碼如下。
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function CheckAll()
{
var gv=document.getElementById("GV");
var items=gv.getElementsByTagName("input");
for (var i=0;i<items.length;i++)
{
if (items[i].type=="checkbox")
{
items[i].checked=document.getElementById("SelectAll").checked;;
}
}
}
</script>
<style type="text/css">
.Freezing
{
position:relative;
table-layout:fixed;
top:expression(this.offsetParent.scrollTop);
z-index:10;
}
.Freezing th{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:2px;}
</style>
<style type="text/css">
html,body,form{margin:0;height:100%}
#SelectAll
{
width: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="width:100%;height:75%;margin:0 auto; text-align:center ">
<div style="text-align:left">
<p style="text-align:left;font-size: large; color:Red">
系統功能>>>></p>
<asp:Button ID="Upload" runat="server"
OnClientClick="return ConfirmUpload()" Style="width: 69px;"
Text="全部上傳" />
<input id="SelectAll" type="checkbox" onclick="return CheckAll()" />全選/全不選
小計余額(萬元)
<asp:TextBox ID="最小余額" runat="server" Text="10" style="text-align:right" Width="100px"></asp:TextBox>
至
<asp:TextBox ID="最大余額" runat="server" Text="20" style="text-align:right" Width="100px"></asp:TextBox>
產品型別
<asp:DropDownList ID="產品型別" runat="server" Height="16px" Width="100px"></asp:DropDownList>
<asp:Button ID="查詢" runat="server" Text="查詢" Width="62px" />
<br />
</div>
<div>
<asp:Panel ID="Panel1" runat="server" Height="100%" Width="100%" ScrollBars="Both">
<asp:GridView ID="GV" runat="server"
AutoGenerateColumns="False"
DataKeyNames="賬號"
BackColor="White" BorderColor="#003366" BorderStyle="Double" BorderWidth="1px"
CellPadding="4" Width="97%" EmptyDataText="沒有記錄!"
HorizontalAlign="Center"
Font-Size="Small" Height="101px">
<HeaderStyle BackColor="#99FF99" Font-Bold="True" HorizontalAlign="Center"
Height="18pt" />
<RowStyle BackColor="#F7F7DE" Height="15px" />
<EmptyDataRowStyle BackColor="#FFFFCC" Height="40px" HorizontalAlign="Center"
VerticalAlign="Middle" />
<Columns>
<asp:BoundField DataField="客戶編號" HeaderText="客戶編號" >
<ItemStyle HorizontalAlign="Left" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="賬號" HeaderText="賬號" >
<ItemStyle HorizontalAlign="Left" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="到期日期" HeaderText="到期日期"
DataFormatString="{0:yyyy/MM/dd}">
<ItemStyle HorizontalAlign="Left" Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="產品型別" HeaderText="產品型別" >
<ItemStyle HorizontalAlign="Left" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="產品名稱" HeaderText="產品名稱" >
<ItemStyle HorizontalAlign="Left" Width="150px" />
</asp:BoundField>
<asp:TemplateField HeaderText="選擇標志">
<HeaderTemplate >
<input id="SelectAll" type="checkbox" onclick="return CheckAll()" />
</HeaderTemplate>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<ItemStyle Height="5px" Width="30px" />
</asp:TemplateField>
<asp:BoundField DataField="賬戶余額" HeaderText="賬戶余額"
DataFormatString="{0:F}">
<ItemStyle HorizontalAlign="Left" Width="80px" />
</asp:BoundField>
<asp:TemplateField HeaderText="上傳結果" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" Width="200px" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
沒有記錄!
</EmptyDataTemplate>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle CssClass="Freezing" />
</asp:GridView>
</asp:Panel>
</div>
<asp:Label ID="回傳記錄數量" runat="server" ForeColor="Red" Text="回傳記錄數量"
Width="150px"></asp:Label>
</div>
</form>
</body>
</html>
uj5u.com熱心網友回復:
各位大蝦有沒有碰過這種情況?uj5u.com熱心網友回復:
用樣式做列凍結,可能會隨著GridView控制元件的特性,在一些操作后不可控嘗試用成型技術(jQuery)等去處理比較好。
https://blog.csdn.net/lxw16601117019/article/details/80618221
uj5u.com熱心網友回復:
這個屬性里應該有吧轉載請註明出處,本文鏈接:https://www.uj5u.com/net/32842.html
標籤:ASP.NET
