zoukankan      html  css  js  c++  java
  • webform简单控件与复合控件

    表单元素:

    文本类:  --简单控件
    文本框:<input type="text" /> 
    密码框:<input type="password" />
    文本域:<textarea></textarea> 
    隐藏域:<input type="hidden" /> 

    按钮类:  --简单控件
    普通按钮:<input type="button" value="按钮1" />
    提交按钮:<input type="submit" value="提交" />
    重置按钮:<input type="reset" value="重置" />
    图片按钮:<input type="image" src="" />

    选择类:  --复合控件
    单选框:<input type="radio" />
    复选框:<input type="checkbox" />

    下拉列表:<select>
         <option></option>
         </select>

    文件选择:<input type="file" />

    二、复合控件
    1、RadioButton 和 CkeckBox不建议使用
    (1)在HTML中的Radio在单击单选按钮后面的文字时不选中
    解决方法:<Label far="nan">男</label>
    (2)RadioButton分组的属性GroupName

    2、RadioButtonList和DropDownList
    这两个控件都是单选,DropDownList没有布局
    (1)绑定上数据
    1)编辑列
    2)查数据库,写在Page_Load中
    方法一:遍历集合

              List<Nation> list = new NationData().Select();
               foreach (Nation n in list)
                {
                    ListItem li = new ListItem(n.NationName, n.NationCode);
                    RadioButtonList1.Items.Add(li);
                }

    方法二:数据源

              List<Nation> list = new NationData().Select();
               RadioButtonList1.DataSource = list;//数据源指向
                RadioButtonList1.DataTextField = "NationName";//显示值
                RadioButtonList1.DataValueField = "NationCode";//实际值
                RadioButtonList1.DataBind();//绑定

    (2)选中数据
    默认数据必须if(IsPostBack){}

    RadioButtonList1.SelectedIndex = 0;//索引
      RadioButtonList1.SelectedValue = "N001";//实际值

    (3)取值

            Label1.Text = "";
            ListItem li = RadioButtonList1.SelectedItem;
            Label1.Text += li.Value + "," + li.Text;

    (4)布局
    RepeatDirection 布局方向 
    Vertical垂直 Horizontal水平
    RepeatColumms 布局项的列数

    3、CkeckBoxList 和ListBox
    这两个数据都是多选,ListBox没有布局。
    ListBox修改属性SelectionMode可选多条。

    (1)绑定上数据

    建议使用遍历集合


    (2)选中数据
    默认数据必须if(IsPostBack){}

    可选多个遍历集合

    复制代码
             foreach (Nation n in list)
                {
                    ListItem li = new ListItem(n.NationName, n.NationCode);
                    if (li.Value == "N001" || li.Value == "N003")
                        li.Selected = true;
                    CheckBoxList1.Items.Add(li);
                }
    复制代码

    (3)取值

    复制代码
           Label1.Text = "";
            foreach (ListItem li in CheckBoxList1.Items)
            {
                if (li.Selected)
                {
                    Label1.Text += li.Value + "," + li.Text + "|";
                }
            }
    复制代码

    (4)布局
    RepeatDirection 布局方向 
    Vertical垂直 Horizontal水平
    RepeatColumms 布局项的列数

  • 相关阅读:
    axis2 WebService 请求参数xml格式
    钉钉扫码登录第三方,appSecret签名算法(附包名)
    win10 IE浏览器中,设置指定程序查看源文件,设置查看源默认程序
    myeclipse CI 2018.8.0和 myeclipse 10 禁止空格自动上屏,自动补全插件
    开发必备网站记录
    二叉树的前序中序后序遍历(简洁)
    贪心算法入门
    Java-二分查找与二叉树关系详解-2021-7-20
    Visual Studio Code快速创建模板(html等)
    java 面向对象1之继承
  • 原文地址:https://www.cnblogs.com/yx1314520/p/5965912.html
Copyright © 2011-2022 走看看