Output multiplication table with lable control


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 
  <form runat="server"> 
  <asp:Table ID="Table1" runat="server"> 
    <asp:Table ID="Table2" runat="server"> 
    <asp:Table ID="Table3" runat="server"> 
    <asp:Table ID="Table4" runat="server"> 
    <asp:Table ID="Table5" runat="server"> 
    <asp:Table ID="Table6" runat="server"> 
    <asp:Table ID="Table7" runat="server"> 
    <asp:Table ID="Table8" runat="server"> 
    <asp:Table ID="Table9" runat="server"> 

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(); 
        for (int c = 0; c < r + 1; c++) 
          TableCell tc = new TableCell(); 
          if (c <= r) 
            table.Rows[r].Cells[c].Text = ((r + 1)).ToString() + '×' + ((c + 1)).ToString() + '=' + (((r + 1) * (c + 1))).ToString(); 

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.

Recommended Today

Analysis of super comprehensive MySQL statement locking (Part 1)

A series of articles: Analysis of super comprehensive MySQL statement locking (Part 1) Analysis of super comprehensive MySQL statement locking (Part 2) Analysis of super comprehensive MySQL statement locking (Part 2) Preparation in advance Build a system to store heroes of the Three KingdomsheroTable: CREATE TABLE hero ( number INT, name VARCHAR(100), country varchar(100), PRIMARY […]