zoukankan      html  css  js  c++  java
  • web网页【2】

    前端代码:

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

    <!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 id="div_chk"
    style = "1000px;border:3px outset #dd9900;margin:54px auto 0 auto;backgroup:red"
    runat="server">
    你学过的课程有:<br/>
    <asp:CheckBox ID="C1" Text = "数据库原理" Width = "260px" runat="server" />
    <asp:CheckBox ID="C3" Text = "操作系统" Width = "260px" runat="server" />
    <asp:CheckBox ID="C5" Text = "c语言" Width = "260px" runat="server" />
    <asp:CheckBox ID="C6" Text = "计算机网络" Width = "260px" runat="server" />
    <asp:CheckBox ID="C7" Text = "管理学" Width = "260px" runat="server" />
    <asp:CheckBox ID="C8" Text = "电子商务" Width = "260px" runat="server" />
    <asp:CheckBox ID="C9" Text = "计算机基础" Width = "260px" runat="server" />
    <br/>
    <asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click" />
    <br/>
    <asp:TextBox ID="TextBox1" TextMode ="Multiline" Rows = "6" runat="server"></asp:TextBox>
    <br/>
    <br/>
    <asp:TextBox ID="TextBox2" TextMode ="Multiline" Rows = "6" runat="server"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" Text="确定" onclick="Button2_Click" />
    <br/>
    <br/>
    <div id = "div_sun" runat = "server">
    <asp:Button ID="Button3" runat="server" Text="Button" />
    <asp:Button ID="Button4" runat="server" Text="Button" />
    <asp:Button ID="Button5" runat="server" Text="Button" />
    <asp:Button ID="Button6" runat="server" Text="Button" />
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    </div>
    <asp:Button ID="Button7" runat="server" Text="显示控件个数" onclick="Button7_Click" />
    </div>
    </form>
    </body>
    </html>

      后端代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            CheckBox  chk;
            foreach(Control _ctl in div_chk.Controls){
                if(_ctl is CheckBox){
                chk = (CheckBox)_ctl;
                    if(chk.Checked == true){
                    TextBox1.Text +=chk.Text+",";
    
                    }
    
                }
            }
      
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            char[] str1 = "abcdefg!".ToCharArray();
            foreach (char ch in str1)
            {
                TextBox2.Text += ch.ToString() + Convert.ToChar(13);
    
            }
        }
        protected void Button7_Click(object sender, EventArgs e)
        {
         
            Button bu;
            TextBox te;
            int i=0;
            int j=0;
            foreach (Control bt in div_sun.Controls)
            {
    
                if (bt is Button) {
                    i++;
                }
    
                if (bt is TextBox) {
                    j++;
                }
    
            }
            Response.Write("按钮控件"+i.ToString() + "个" + "</br>");
            Response.Write("文本框控件" + j.ToString() + "个" + "</br>");
        }
    }
    

      

  • 相关阅读:
    形象理解ERP(转)
    禁用windows server 2008 域密码复杂性要求策略
    How to adding find,filter,remove filter on display method Form
    Windows Server 2008 R2激活工具
    How to using bat command running VS development SSRS report
    Creating Your First Mac AppGetting Started
    Creating Your First Mac AppAdding a Track Object 添加一个 Track 对象
    Creating Your First Mac AppImplementing Action Methods 实现动作方法
    Creating Your First Mac AppReviewing the Code 审查代码
    Creating Your First Mac AppConfiguring the window 设置窗口
  • 原文地址:https://www.cnblogs.com/sunyubin/p/9636147.html
Copyright © 2011-2022 走看看