• 复合控件


    1、label。后台编译Span

    (1)ForeColor字体颜色

    (2)设置label的Height,Width之前,必须先设置:Display=“inLine-block”;

    (3)Text:文本内容。

    (4)visible:权限使用

    (5)CssClass:使用的样式表

    2、Literal。后台编译啥也没有

    (1)Text:文本内容。

    但是可以对Literal添加事件。+= Tab Tab

    3、表单元素

    (1)文本元素

    <input type="text" />  工具栏的TextBox的TextMode:SingleLine

    <input type="password" /> 工具栏的TextBox的TextMode:Password

    <input type="textarea" />工具栏的TextBox的TextMode:MultiLine

    <input type="hidden" />设置:display:none

    工具栏的TextBox的TextMode:Color:颜色选择框

    工具栏的TextBox的TextMode:Date:日期格式文本框

    (2)按钮元素

    <input type="button" /> 点击它就是执行赋予的点击事件,不刷新网页

    <input type="submit" />刷新网页,把表单元素的内容提交

    <input type="resit" />不刷新网页,把表单元素的内容清空。

    <input type="image" />刷新网页。

    工具栏的LinkButton:当做有链结的按钮

    ImageButton:当做图片的按钮

    OnClientClick:脚本的点击事件,里面必须写js语言。按钮的OnClientClick是执行客户端脚本(js),客户端执行优先级高于服务端

    (3)复选框元素

    ①<input type="radio">单选

    //工具栏
    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="sex" Text="" /> 
    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="sex" Text="" />
    //表单元素
    <input type="radio"  name="sex" id="nan"/><label for="nan">男</label>
     <input  type="radio" name="sex" id="nv" /><label for="nv">女</label>

    ②<input type="checkbox">多线

    ③<input type="file">路径

    ④<select>下拉框

    <option></option>

    </select>

     复合框要做到三步:(以RadioButtonList为例)

    (1)将数据绑定上去(数据库表为Nation,有NationCode和NationName两列)

    先进封装,设置一个返回List<Nation>的方法

    (2)设置默认选中数据

    (3)竞选中数据取出来。如下代码:

    方法1:

    using System;
    using System.Collections.Generic;
    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)
        {
            Button1.Click += Button1_Click;//赋予按钮1的点击事件
            if (IsPostBack == false)
            {
                List<Nation> nlist= new NationData().quan();//获取全部内容
                if (IsPostBack == false)//页面重新加载时显示的内容
                {
                    RadioButtonList1.DataSource = nlist;//数据源指向
                    RadioButtonList1.DataValueField = "NationCode";//设置Value值
                    RadioButtonList1.DataTextField = "NationName";//设置显示内容
                    RadioButtonList1.DataBind();//数据最后绑定
                }   
            }
        }
    
        void Button1_Click(object sender, EventArgs e)//按钮1的点击事件
        {
            ListItem li = RadioButtonList1.SelectedItem;//获取选中内容
            Label1.Text = li.Value + li.Text;//输出选中的代号和名字
        }
    }
    View Code

    方法2:

    using System;
    using System.Collections.Generic;
    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)
        {
            Button1.Click += Button1_Click;//赋予按钮1的点击事件
            if (IsPostBack == false)
            {
                List<Nation> nlist= new NationData().quan();//获取全部内容
                foreach (Nation n in nlist)//用遍历方法,用集合方式添加进去
                {
                    ListItem li = new ListItem(n.NationName, n.NationCode);//设置Text和Value值
                    RadioButtonList1.Items.Add(li);//添加集合
                
                }
                RadioButtonList1.SelectedIndex = 0;//设置默认值
            }
        }
    
        void Button1_Click(object sender, EventArgs e)//按钮1的点击事件
        {
            ListItem li = RadioButtonList1.SelectedItem;//获取选中内容
            Label1.Text = li.Value + li.Text;//输出选中的代号和名字
        }
    }
    View Code

    (4)布局
    RepeatDirection:项的布局方式 Vertical 纵向 Horizontal:横向
    RepeatColumns:规定项的列数
    RepeatLayout:项的布局方式 Table Flow (UnorderedList:无序列表 OrderedList:有序列表 前两种属性无效)。

  • 相关阅读:
    第2课 有符号与无符号
    第1课 基本数据类型
    HDU 5821 Ball
    Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
    HDU 5810 Balls and Boxes
    HDU 5818 Joint Stacks
    HDU 5813 Elegant Construction
    Codeforces Round #357 (Div. 2)C. Heap Operations
    Codeforces Round #364 (Div. 2) C. They Are Everywhere
    HDU5806 NanoApe Loves Sequence Ⅱ
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/5959824.html
Copyright © 2020-2023  润新知