当前位置: 移动技术网 > IT编程>开发语言>.net > 使用Lable控件输出九九乘法表

使用Lable控件输出九九乘法表

2017年11月17日  | 移动技术网IT编程  | 我要评论

侠盗飞车下水秘籍,松原旅游景点大全,彼岸有妖txt

利用lable控件输出九九乘法表,具体内容如下

首先建立一个空网站,之后选择添加新项,添加一个web窗体。
进入.aspx文件之后,在设计界面中添加9个lable控件。lable控件在标准组中。得到的源代码是这样的。

<%@ page language="c#" autoeventwireup="true" codefile="webform4.aspx.cs" inherits="webform4" %> 
 
<!doctype html> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
  <title>九九乘法表</title> 
</head> 
<body> 
  <form id="form1" runat="server"> 
  <div> 
  <asp:table id="table1" runat="server"> 
    </asp:table> 
    <asp:table id="table2" runat="server"> 
    </asp:table> 
    <asp:table id="table3" runat="server"> 
    </asp:table> 
    <asp:table id="table4" runat="server"> 
    </asp:table> 
    <asp:table id="table5" runat="server"> 
    </asp:table> 
    <asp:table id="table6" runat="server"> 
    </asp:table> 
    <asp:table id="table7" runat="server"> 
    </asp:table> 
    <asp:table id="table8" runat="server"> 
    </asp:table> 
    <asp:table id="table9" runat="server"> 
    </asp:table> 
  </div> 
  </form> 
</body> 
</html> 

接着,要实现九九乘法表的创建,还需要在.aspx.cs文件添加代码。

using system; 
using system.collections.generic; 
using system.linq; 
using system.web; 
using system.web.ui; 
using system.web.ui.webcontrols; 
 
public partial class webform4 : system.web.ui.page 
{ 
  protected void page_load(object sender, eventargs e) 
  { 
    if (!ispostback) 
    { 
      table table = new table(); 
 
      for (int r = 0; r < 9; r++) 
      { 
        tablerow tr = new tablerow(); 
        table.rows.add(tr); 
        for (int c = 0; c < r + 1; c++) 
        { 
          tablecell tc = new tablecell(); 
          tr.cells.add(tc); 
          if (c <= r) 
            table.rows[r].cells[c].text = ((r + 1)).tostring() + '×' + ((c + 1)).tostring() + '=' + (((r + 1) * (c + 1))).tostring(); 
        } 
      } 
      form1.controls.add(table); 
    } 
  } 
} 

运行程序,得到的效果图如下:

这样,一个九九乘法表就输出来啦!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网