读书人

gridview显示有关问题

发布时间: 2012-04-11 17:42:33 作者: rapoo

gridview显示问题
如何创建表头固定,表体可滚动的GridView!


以下代码显示时,表头不见了
<script runat= "server ">
protected void Page_Load( object sender, EventArgs e )
{
if (!IsPostBack)
{
GridView1.Attributes.Add( "style ", "table-layout:fixed ");
GridView1.DataSource = dt.DefaultView;
//dt已经绑定数据源!
GridView1.DataBind();
}
}
</script>

<script type= "text/javascript ">
function s()
{
var t = document.getElementById( " <%=GridView1.ClientID%> ");
var t2 = t.cloneNode(true)
for(i = t2.rows.length -1;i > 0;i--)
t2.deleteRow(i)
t.deleteRow(0)
a.appendChild(t2)
}
window.onload = s
</script>

<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> 创建表头固定,表体可滚动的GridView </title>
</head>
<body>
<form id= "Form1 " runat= "server ">
<table>
<tr>
<td>
<div id= "a ">
</div>
<div style= "overflow-y: scroll; height: 200px ">
<asp:GridView ID= "GridView1 " runat= "server " Font-Size= "12px " BackColor= "#FFFFFF "


GridLines= "Both " CellPadding= "4 " Width= "560 ">
<HeaderStyle BackColor= "#EDEDED " Height= "26px " />
</asp:GridView>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>


[解决办法]
试试在GridView的模板中添加 <div> 把div的style里面的scrollbars属性设置为yes

读书人网 >asp.net

热点推荐