Output multiplication table with lable control

Time:2020-11-13

Use the lable control to output the multiplication table. The details are as follows

First create an empty web site, and then choose to add a new item to add a web form.
After entering the. ASPX file, add 9 lable controls in the design interface. The label control is in the standard group. The source code is like this.

<%@ 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 > multiplication table 
</head> 
<body> 
  <form 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>

Next, in order to create the multiplication table, you need to set up the multiplication table in aspx.cs File add code.


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); 
    } 
  } 
} 

Running the program, the effect picture is as follows:

In this way, a multiplication table will be output!

The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.