当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > DataGrid表头不动,表身动

ASP.NET
在ASP.NET中自动给URL加上超级链接
在ASP.NET中怎么用Session判断用户是否登录?
C#是一种新的语言?或者仅仅只是Java
在网页中动态的生成一个图片
C#实现的18位身份证格式验证算法
Asp.net中的页面乱码的问题
ASP.NET中利用存储过程实现模糊查询
ASP.NET 2.0中构造个性化网页
.net教程:ASP.NET GridView的分页功能
ASP.Net中无刷新执行Session身份验证
用事实说话!AJAX应用程序开发七宗罪
迁移你的Web页面到ASP.NET AJAX 1.0
SQL Server 2005中插入XML数据方法
编程技巧 用Asp.net动态生成html页面
在asp.net 2.0 中使用的存储过程解析
用 asp.net 动态设置 WebService 引用
新手入门之ASP.NET2.0中的缓存技术解析
asp.net编程中实现 MD5 加密
ASP.NET备份恢复SqlServer数据库
Asp.Net输出数据到EXCEL表格中

ASP.NET 中的 DataGrid表头不动,表身动


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 116 ::
收藏到网摘: n/a

上次和海东兄讨论了这个问题,但是他的表头没有线,所以用Div形式实现了,实现功能显示表格,代码如下(后台.cs文件只要绑定数据就可以了,字段和前台绑定的一致就OK了,在此不加赘述):

<%@ Page language="c#" Codebehind="dg1.aspx.cs" AutoEventWireup="false" Inherits="netLearn.dg1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>dg1</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  <script language="javascript">
  function window.onload()
  {
   var dg = document.getElementById('DataGrid1');
   var strHTML = "";
   for( var i=1; i<dg.rows.length;i++)
   {
    strHTML += dg.rows[i].cells[0].innerHTML;
   }  
   dg.rows[1].cells[0].innerHTML = "<div id='dgContent' style='height:250px;overflow-y:scroll'>" + strHTML + "</div>";
   for( var i=dg.rows.length-1; i>1;i--)
   {
    dg.deleteRow(i);
   }
  }
  </script>

 </HEAD>
 <body MS_POSITIONING="FlowLayout">
  <form id="Form1" method="post" runat="server">
   <FONT face="宋体">
    <asp:datagrid id="DataGrid1" runat="server" Width="576px" Height="192px" AutoGenerateColumns="False"
     BorderWidth="0px" CellPadding="0">
     <Columns>
      <asp:TemplateColumn>
       <HeaderTemplate>
        <table cellpadding="2" cellspacing="1" bgcolor="PaleTurquoise" width="100%">
         <tr>
          <th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
           序号</td>
           <th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
            ID号</td>
            <th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
             姓名</td>
             <th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
          年龄</td>
         </tr>
        </table>
       </HeaderTemplate>
       <ItemTemplate>
        <table cellpadding="2" cellspacing="1" bgcolor="PaleTurquoise" width="100%">
         <tr>
          <td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#Container.ItemIndex+1%></td>
          <td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"ID")%></td>
          <td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"Name")%></td>
          <td bgcolor="LightSkyBlue" width="23%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"Age")%></td>
         </tr>
        </table>
       </ItemTemplate>
      </asp:TemplateColumn>
     </Columns>
    </asp:datagrid></FONT></form>


 </body>
</HTML>

效果如下: