在panel里的gridview固定表头后表头超出panel的范围了
将gridview放在panel里,设置panel的滚动条,然后在page_load里加入代码:protectedvoidPage_Load(objectsender,E...
将gridview放在panel里,设置panel的滚动条,然后在page_load里加入代码:protected void Page_Load(object sender, EventArgs e)
{
GridView1.HeaderRow.Attributes.Add("style", "z-index:999;position:relative;top:expression(this.offsetParent.scrollTop);");
}
出现问题:表头固定了,但是由于表头很多,所以,表头超出panel范围,而且也不能随着水平滚动条移动。
各位帮帮忙啊!
谢谢上面两位,我两个方法都试了,gridview的width设为100%,效果还是原来那样,panel的width设为100%,gridview的宽度和屏幕大小相匹配了,但是还是有表头在panel外面。
我想要这样的效果,panel的水平和垂直滚动条都要,拉动垂直滚动条时,表头不动表体内容滚动,拉动水平滚动条时,表头和表体都随着水平滚动条的移动而移动。麻烦大家再帮我一起想想啊,谢谢!
我把代码放在83yanzi的回答里了,麻烦帮我看一下,谢谢! 展开
{
GridView1.HeaderRow.Attributes.Add("style", "z-index:999;position:relative;top:expression(this.offsetParent.scrollTop);");
}
出现问题:表头固定了,但是由于表头很多,所以,表头超出panel范围,而且也不能随着水平滚动条移动。
各位帮帮忙啊!
谢谢上面两位,我两个方法都试了,gridview的width设为100%,效果还是原来那样,panel的width设为100%,gridview的宽度和屏幕大小相匹配了,但是还是有表头在panel外面。
我想要这样的效果,panel的水平和垂直滚动条都要,拉动垂直滚动条时,表头不动表体内容滚动,拉动水平滚动条时,表头和表体都随着水平滚动条的移动而移动。麻烦大家再帮我一起想想啊,谢谢!
我把代码放在83yanzi的回答里了,麻烦帮我看一下,谢谢! 展开
4个回答
展开全部
你好,我是83scharf,代码如下
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="panel.aspx.cs" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="445px" ScrollBars="Both" Width="525px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="inquireId" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="inquireId" HeaderText="inquireId" ReadOnly="True" SortExpression="inquireId" />
<asp:BoundField DataField="fixedAssetId" HeaderText="fixedAssetId" SortExpression="fixedAssetId" />
<asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />
<asp:BoundField DataField="softType" HeaderText="softType" SortExpression="softType" />
<asp:BoundField DataField="brandOrSoftname" HeaderText="brandOrSoftname" SortExpression="brandOrSoftname" />
<asp:BoundField DataField="productModelOrEdition" HeaderText="productModelOrEdition"
SortExpression="productModelOrEdition" />
<asp:BoundField DataField="configuration" HeaderText="configuration" SortExpression="configuration" />
<asp:BoundField DataField="servicetag" HeaderText="servicetag" SortExpression="servicetag" />
<asp:BoundField DataField="os" HeaderText="os" SortExpression="os" />
<asp:BoundField DataField="warranty" HeaderText="warranty" SortExpression="warranty" />
<asp:BoundField DataField="annualCost" HeaderText="annualCost" SortExpression="annualCost" />
<asp:BoundField DataField="purchaseDate" HeaderText="purchaseDate" SortExpression="purchaseDate" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="ownCompany" HeaderText="ownCompany" SortExpression="ownCompany" />
<asp:BoundField DataField="principal" HeaderText="principal" SortExpression="principal" />
<asp:BoundField DataField="useCompany" HeaderText="useCompany" SortExpression="useCompany" />
<asp:BoundField DataField="usePlace" HeaderText="usePlace" SortExpression="usePlace" />
<asp:BoundField DataField="useDepartment" HeaderText="useDepartment" SortExpression="useDepartment" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="userNumber" HeaderText="userNumber" SortExpression="userNumber" />
<asp:BoundField DataField="audit" HeaderText="audit" SortExpression="audit" />
<asp:BoundField DataField="auditDate" HeaderText="auditDate" SortExpression="auditDate" />
<asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
<asp:BoundField DataField="changeId" HeaderText="changeId" SortExpression="changeId" />
<asp:BoundField DataField="remark" HeaderText="remark" SortExpression="remark" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sql_XellaConnectionString %>"
SelectCommand="SELECT * FROM [tb_ITInfo]"></asp:SqlDataSource>
</asp:Panel>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.HeaderRow.Attributes.Add("style", "z-index:999;position:relative;top:expression(this.offsetParent.scrollTop);");
}
}
谢谢,麻烦帮我看看!
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="panel.aspx.cs" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="445px" ScrollBars="Both" Width="525px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="inquireId" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="inquireId" HeaderText="inquireId" ReadOnly="True" SortExpression="inquireId" />
<asp:BoundField DataField="fixedAssetId" HeaderText="fixedAssetId" SortExpression="fixedAssetId" />
<asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />
<asp:BoundField DataField="softType" HeaderText="softType" SortExpression="softType" />
<asp:BoundField DataField="brandOrSoftname" HeaderText="brandOrSoftname" SortExpression="brandOrSoftname" />
<asp:BoundField DataField="productModelOrEdition" HeaderText="productModelOrEdition"
SortExpression="productModelOrEdition" />
<asp:BoundField DataField="configuration" HeaderText="configuration" SortExpression="configuration" />
<asp:BoundField DataField="servicetag" HeaderText="servicetag" SortExpression="servicetag" />
<asp:BoundField DataField="os" HeaderText="os" SortExpression="os" />
<asp:BoundField DataField="warranty" HeaderText="warranty" SortExpression="warranty" />
<asp:BoundField DataField="annualCost" HeaderText="annualCost" SortExpression="annualCost" />
<asp:BoundField DataField="purchaseDate" HeaderText="purchaseDate" SortExpression="purchaseDate" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="ownCompany" HeaderText="ownCompany" SortExpression="ownCompany" />
<asp:BoundField DataField="principal" HeaderText="principal" SortExpression="principal" />
<asp:BoundField DataField="useCompany" HeaderText="useCompany" SortExpression="useCompany" />
<asp:BoundField DataField="usePlace" HeaderText="usePlace" SortExpression="usePlace" />
<asp:BoundField DataField="useDepartment" HeaderText="useDepartment" SortExpression="useDepartment" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="userNumber" HeaderText="userNumber" SortExpression="userNumber" />
<asp:BoundField DataField="audit" HeaderText="audit" SortExpression="audit" />
<asp:BoundField DataField="auditDate" HeaderText="auditDate" SortExpression="auditDate" />
<asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
<asp:BoundField DataField="changeId" HeaderText="changeId" SortExpression="changeId" />
<asp:BoundField DataField="remark" HeaderText="remark" SortExpression="remark" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sql_XellaConnectionString %>"
SelectCommand="SELECT * FROM [tb_ITInfo]"></asp:SqlDataSource>
</asp:Panel>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.HeaderRow.Attributes.Add("style", "z-index:999;position:relative;top:expression(this.offsetParent.scrollTop);");
}
}
谢谢,麻烦帮我看看!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我测试了一下,结果和你想要的是一样的,怎么你就是错的呢,能不能把具体代码贴出来,我帮你看看
--补充:我的测试结果
不要用SqlDataSource来绑定数据源,这样的话表头就会出去
你可以自己写一个连接数据库的方法,然后用Dataset去绑定到GridView
这样在显示的时候绝对没问题
--补充:我的测试结果
不要用SqlDataSource来绑定数据源,这样的话表头就会出去
你可以自己写一个连接数据库的方法,然后用Dataset去绑定到GridView
这样在显示的时候绝对没问题
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把GridView1的宽度设置width="100%";试试。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
设置Panel Width="100%"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询