• GridView根据一列自动计算(转载)


    <%@ Page Language="C#" %>
     
    <%@ Import Namespace="System.Xml" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <script runat="server">
     
      protected void Page_Load(object sender, EventArgs e)
      {
     
        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 < 8; 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, 0);
          dr[3] = System.Math.Round(rd.NextDouble() * 100, 0);
          dr[4] = System.Math.Round(rd.NextDouble() * 100, 0);
          dr[5] = System.Math.Round(rd.NextDouble() * 100, 0);
          dt.Rows.Add(dr);
        }
        System.Data.DataView dv = new System.Data.DataView(dt);
        GridView1.DataSource = dv;
        GridView1.DataBind();
      }
    </script>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title></title>
      <script>
    
          function Gen(t) {
              var tr = t.parentNode;
              while (tr.tagName != "TR") {
                  tr = tr.parentNode;
              }
              if (!tr) {
                  return;
              }
              if (tr.tagName != "TR") {
                  return;
              }
              if (t.value != "" && !isNaN(parseInt(t.value, 10)))
                  tr.cells[2].getElementsByTagName("span")[0].innerHTML = parseInt(t.value, 10) + parseInt(tr.cells[1].innerHTML)
    
          }
       
      </script>
    </head>
    <body>
      <form id="form1" runat="server">
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
      <Columns>
      <asp:TemplateField><ItemTemplate>输入:<asp:textBox id="t" runat="server" onblur="Gen(this)"></asp:textBox></ItemTemplate></asp:TemplateField>
      <asp:BoundField DataField="数学" />
      <asp:TemplateField>
      <ItemTemplate>总计:<span></span></ItemTemplate></asp:TemplateField>
      </Columns>
      </asp:GridView>
      </form>
    </body>
    </html>
    
  • 相关阅读:
    MCS-51系列单片机和MCS-52系列单片机有何异同
    51单片机指令表
    ROM、PROM、EPROM、EEPROM、Flash ROM分别指什么?
    用最简单的办法轻松区分无源晶振和有源晶振
    CE310A
    夏普sharp复印机安装视频及教导
    SHARP AR-2048D/2348D
    SHARP 加粉1
    SHARP 加粉
    SQL SERVER BOOK
  • 原文地址:https://www.cnblogs.com/niuge/p/5565560.html
Copyright © 2020-2023  润新知