当前位置导航:炫浪网>>网络学院>>编程开发>>Visual C#教程

创建表头固定,表体可滚动的GridView

本方法只需要设置一个GridView的宽度,其它宽度不需要设置。测试环境:IE6,Firefox通过。

C#

<%@ Page Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 计算数据,完全可以从数据看取得 ICollection CreateDataSource( ) { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("学生班级", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal))); for (int i = 0; i < 50; i++) { System.Random rd = new System.Random(Environment.TickCount * i); ; dr = dt.NewRow(); dr[0] = "班级" + i.ToString(); dr[1] = "【孟子E章】" + i.ToString(); dr[2] = System.Math.Round(rd.NextDouble() * 100, 2); dr[3] = System.Math.Round(rd.NextDouble() * 100, 2); dr[4] = System.Math.Round(rd.NextDouble() * 100, 2); dr[5] = System.Math.Round(rd.NextDouble() * 100, 2); dt.Rows.Add(dr); } System.Data.DataView dv = new System.Data.DataView(dt); return dv; } protected void Page_Load( object sender, EventArgs e ) { if (!IsPostBack) { GridView1.Attributes.Add("style", "table-layout:fixed"); GridView1.DataSource = CreateDataSource(); 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"> <HeaderStyle BackColor="#EDEDED" Height="26px" /> </form> </div> </div> <div class="c_bot_text"><span id="pe100_page_contentpage" class="pagecss"></span></div> <div class="c_bot_text"> <div class="clearbox"></div> </div> <div class="c_bot_text"><font style="color:red">上一篇:</font><a href="/html/68654.html" target="_self">c# 连接字符串数据库服务器端口号</a> <font style="color:red">下一篇:</font><a href="/html/68656.html" target="_self">用C#制作PDF文件全攻略</a></div> <div class="clearbox"></div> <div class="lm_xxlb_title"> <div class="title">相关内容</div> <div class="more"> <a href="/list_199/index.html">[更多] </a> </div> </div> <div class="flm_xxlb_main"> <div class="clearbox"></div> <ul> <li> <div class="tydlmxxlb_title"><a href="/html/68681.html" target="_blank">C# WinForm下DataGridView单元按钮列</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68680.html" target="_blank">MRS实现和扩展一个Service Contract</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68679.html" target="_blank">C++、Java与C#的命名规范总结</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68678.html" target="_blank">C# 2010命名和可选参数的新特性</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68677.html" target="_blank">C#抽象类与接口的区别</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68676.html" target="_blank">全面剖析C#接口编程之定义接口</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68675.html" target="_blank">引用第三方类库的私有类与私有方法</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68674.html" target="_blank">认识C# Tips浅拷贝和深拷贝</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68673.html" target="_blank">GridView实现用“...”代替超长字符串</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68672.html" target="_blank">C#中对DatagridView的部分常用操作</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68671.html" target="_blank">讨论:C# 4.0新特性dynamic有何用?</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68670.html" target="_blank">C#实现的多线程异步数据包接收器框架</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68669.html" target="_blank">c# 日期函数 string.Format</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68668.html" target="_blank">C#网络版斗地主—出牌权限的传递</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68667.html" target="_blank">c#指针实现进行图像操作</a></div> </li> <li> <div class="tydlmxxlb_title"><a href="/html/68666.html" target="_blank">C#正则表达式高级技巧及实例详解</a></div> </li> </ul> <div class="clearbox"></div> </div> </div> <!-- 主体内容结束 --> </div> <div class="main_right_nr"> <div class="main_right_tit">赞助商链接</div> <div class="ad_lmsct"> <script type="text/javascript" src='/IAA/200902/12.js'></script> </div> </div> <div class="clearbox"></div> </div> <span style="display:none;"> <script language="JavaScript" type="text/JavaScript" src="/Common/GetHits.aspx?id=68655"></script> </span> <div class="main"> <div id="bottom_all"> <div id="foot"> <div id="copyright"> 【注意】炫浪网 版权所有,未经书面授权禁止模仿风格或建立镜像网站.如有违反,追究法律责任.<br /> 【声明】本网站部分内容属社区网友发布,本网站仅提供网友交流平台,但有权在本网站范围内引用、发布、<br /> 转载来自社区网友发布的内容。网友发布内容纯属个人行为,与本网站立场无关。本网站对于网友发布的<br /> 内容所引发的版权、署名权的异议及纠纷,不承担任何责任。 粤ICP备<a href="http://www.miibeian.gov.cn">11064832</a>号 公安备案编号:4453023010550 <script src="http://s96.cnzz.com/stat.php?id=372893&web_id=372893" language="JavaScript"></script> </div> </div> </div> </div> </body> </html>