• 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>
    
  • 相关阅读:
    spring @Transactional 事务注解
    vue 父子组件的方法调用
    spring boot使用TestRestTemplate集成测试 RESTful 接口
    JS实现网站内容的禁止复制和粘贴、另存为
    vue把localhost改成ip地址无法访问—解决方法
    spring mvc spring boot 允许跨域请求 配置类
    JIRA安装过程中链接mysql的问题!
    vue开发中v-for在Eslint的规则检查下出现:Elements in iteration expect to have 'v-bind:key' directives
    Linux进程启动/指令执行方式研究
    反弹Shell原理及检测技术研究
  • 原文地址:https://www.cnblogs.com/niuge/p/5565560.html
Copyright © 2020-2023  润新知