zoukankan      html  css  js  c++  java
  • 利用textbox自动生成一个表格 附详细解释

    <%@ Page Language="VB" debug=true ContentType="text/html" ResponseEncoding="gb2312" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>利用textbox自动生成一个表格</title>
    <script language="vb" runat="server">
    sub btn_click(sender as object,e as eventargs) '声明btn_click过程
    dim introws as integer=cint(rowtxt.text) '声明表格行数=id为rowtxt的textbox控件来的
    dim intcell as integer=cint(celltxt.text) '声明表格列数=id为cellxt的textbox控件来的
    dim j as integer
    dim i as integer
    dim r as tablerow '声明一个tablerow(表格行)对象
    dim c as tablecell '声明一个tablecell(表格列)对象
    dim g as literal '声明一个literal(文字)对象
    dim img as image '声明一个image(图像控件)对象
    for j=0 to introws-1 '因为下标是从0开始的,所以结果会多1出来,为了正确,当然只能减1了
     r=new tablerow() '创建一个tablerow(表格行)对象
      for i=0 to intcell-1
       img=new image() '创建一个image(图像控件)对象
       g=new literal() '创建一个literal(文字)对象
       g.text=j+1 & "-" & i+1 & ".gif" '申明文字的text属性是每循环一次就 加1
       img.imageurl="img/" & j+1 & "-" & i+1 & ".gif"  '申明图像名称属性是每循环一次就 加1
       c=new tablecell() '创建一个tablecell(表格列)对象
       c.controls.add(img) '向单元格中加入一个图像
       c.controls.add(g) '向单元格中加入一个文字
       r.cells.add(c) '向表格行中增加一个单元格
      next
     table1.rows.add(r) '向表格中增加一个表格行
    next 
    end sub
    </script>
    </head>
    <body>
    <form runat="server">
    <asp:TextBox ID="rowtxt" runat="server"/>
    <asp:TextBox ID="celltxt" runat="server"/>
    <asp:Button ID="btn" Text="给我弄个格格" OnClick="btn_click" runat="server"/>
    </form>
    <asp:Table ID="table1" runat="server" CellPadding="10" CellSpacing="2" border="1"/>
    </body>
    </html>

  • 相关阅读:
    ylbtech-LanguageSamples-Indexers_2(索引器)
    ylbtech-LanguageSamples-Indexers(索引器)
    ylbtech-LanguageSamples-Hello World
    ylbtech-LanguageSamples-Generics(泛型)
    Tomcat
    Tomcat中部署WEB项目的四种方法
    解决fonts.gstatic.com无法访问
    关于android的屏幕保持常亮
    求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
    不用加减乘除实现加法
  • 原文地址:https://www.cnblogs.com/thcjp/p/336922.html
Copyright © 2011-2022 走看看