使用Lable控件输出九九乘法表
2017-11-05 15:07
393 查看
利用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); } } }
运行程序,得到的效果图如下:
这样,一个九九乘法表就输出来啦!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 利用Lable控件输出九九乘法表
- 使用while循环语句和变量输出九九乘法表
- 使用循环输出九九乘法表:
- 使用for循环语句输出九九乘法表
- 使用 Repeater 控件,每隔N条数据输出另外的格式
- [iOS]Objective-C中使用for循环打印输出九九乘法表
- python学习习题总结(8)——简单选择排序,列表解析式使用(格式化输出杨辉三角,九九乘法表)
- WPF显示经常使用的几个显示文字控件TextBox, TextBlock, Lable
- 技巧和诀窍:使用ASP.NET 2.0 CSS 控件适配器生成CSS友好的HTML输出
- vs2003 asp.net中直接输出wml,并利用C#做动态页面的控制,不使用微软的移动控件
- Lable和Literal控件的使用和区别
- 使用ASP.NET 2.0 CSS 控件适配器生成CSS友好的HTML输出
- 1 用存储过程实现分页,除了上一页,下一页,第一页,和末页外还要有go按钮,以及go到那里的文本框。另外还要在Lable显示“当前x页,一共y页”。注意验证控件的使用和 链接存储过程的内容。
- 条码控件TBarCode SDK使用教程:为输出设备的分辨率优化条码
- Lable和Literal控件的使用和区别
- asp.net控件开发技巧(1)使用HtmlTextWriter类规范输出标签
- 技巧和诀窍:使用ASP.NET 2.0 CSS 控件适配器生成CSS友好的HTML输出
- 关于VS2013 mfc使用Edit control控件显示输出内容问题
- Lable和Literal控件的使用和区别
- asp.net控件开发技巧(1)使用HtmlTextWriter类规范输出标签