표 대상의 운용table dropdownlist

3215 단어 UIWebXHTMLJ#asp
dropdownlist에서 행, 열을 선택하여 표를 정합니다
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    
        int row = int.Parse(this.DropDownList1.SelectedValue);//       
        int cell = int.Parse(this.DropDownList2.SelectedValue);
        for (int i = 1; i <= row; i++) { //   

            TableRow tr = new TableRow();//       
            for (int j = 1; j<=cell; j++) { //   
            
                TableCell tc=new TableCell();//       
                Label lbl = new Label();//      
                lbl.Text= i.ToString() + " " + j.ToString() + " ";//                
                tc.Controls.Add(lbl);//            
                tr.Controls.Add(tc);//         
            
            }
            Table1.Controls.Add(tr);//           
        }

    }
}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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 runat="server">
    <title>    </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
        </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="  " /><br />
        <br />
        <asp:Table ID="Table1" runat="server" Height="144px" Width="295px">
        </asp:Table>
    
    </div>
    </form>
</body>
</html>

좋은 웹페이지 즐겨찾기