gridview冻结表头会自动消失

frankwong 2020-05-29 05:44:40
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>
...全文
359 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
イω 2020-06-08
  • 打赏
  • 举报
回复
这个属性里应该有吧
  • 打赏
  • 举报
回复
用样式做列冻结,可能会随着GridView控件的特性,在一些操作后不可控 尝试用成型技术(jQuery)等去处理比较好。 https://blog.csdn.net/lxw16601117019/article/details/80618221
frankwong 2020-05-30
  • 打赏
  • 举报
回复
各位大虾有没有碰过这种情况?

62,071

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧