码迷,mamicode.com
首页 > Web开发 > 详细

web网页【2】

时间:2018-09-12 20:09:12      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:prot   数据库原理   cli   gen   char   its   +=   网页   文本   

前端代码:

<%@ 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 = "width: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>");
    }
}

  

web网页【2】

标签:prot   数据库原理   cli   gen   char   its   +=   网页   文本   

原文地址:https://www.cnblogs.com/sunyubin/p/9636147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!