zoukankan      html  css  js  c++  java
  • [原]DataGrid表头不动,表身动

    上次和海东兄讨论了这个问题,但是他的表头没有线,所以用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>

    效果如下:
     
    http://www.cnblogs.com/images/cnblogs_com/skylaugh/69471/r_picDatagrid.bmp
  • 相关阅读:
    codeforces 671B Robin Hood 二分
    HDU 4009 Transfer water 最小树形图
    HDU 2121 Ice_cream’s world II 最小树形图
    UVA1395 Slim Span(枚举最小生成树)
    ZOJ 1107FatMouse and Cheese(BFS)
    POJ2239 Selecting Courses(二分图最大匹配)
    UVA 11419SAM I AM(输出 最小覆盖点 )
    POJ 3678 Katu Puzzle(强连通 法)
    POJ3207Ikki's Story IV
    POJ1236Network of Schools(强连通分量 + 缩点)
  • 原文地址:https://www.cnblogs.com/skylaugh/p/498597.html
Copyright © 2011-2022 走看看