一、简单控件:

1.label控件

<asp:Label ID="Label1" runat="server" Text="账  号:"></asp:Label>

被编译为:

<span id="Label1" >账  号:</span>

属性:

Text:文本
ForeColor:字体颜色
Visible:是否可见
CssClass:即HTML的class

2.Literal

类似label,但它不会被编译,只会在位置上将Text内容完全展示出来,可以往它的Text属性中添加js代码

3.Textbox

不一定被编译成什么元素,它被编译成什么表单元素取决于TextMode,它能够完成form12个表单元素中的文本类(除隐藏域),它还能完成Webform提供的一些元素

(1)文本框

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

它被编译为:

<input name="TextBox1" type="text" id="TextBox1" />

(2)密码框

<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>

它被编译为:

<input name="TextBox2" type="password" id="TextBox2" />

(3)文本域

<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine"></asp:TextBox>

它被编译为:

<textarea name="TextBox3" rows="2" cols="20" id="TextBox3">
</textarea>

(4)TextMode属性

color:只能选择颜色

datetime-local:可选择时间,输入时间,有日历

number:只能输入数字

4.按钮类

普通按钮和重置按钮在Webform没有提供按钮

<input type="button" value="按钮1" />
<input type="reset" value="重置" />

(1)Button

<asp:Button ID="Button1" runat="server" Text="Button" />

它被编译为:

 <input type="submit" name="Button1" value="Button" id="Button1" />/*提交按钮*/

(2)ImageButton

<asp:ImageButton ID="ImageButton1" runat="server" />

它被编译为:

 <input type="image" name="ImageButton1" id="ImageButton1" src="" />/*图片按钮*/

(3)LinkButton 超链接按钮

(4)按钮的OnClientClick是执行客户端脚本(js),客户端(js)执行优先级高于服务端(C#)

5.隐藏域

HiddenField控件

<asp:HiddenField ID="HiddenField1" runat="server" />

它被编译为:

<input type="hidden" name="HiddenField1" id="HiddenField1" />

二、复合控件

1.单选按钮:
HTML编码方式:

<input type="radio" name="" checked="checked"/>

Webform:RadioButton 不建议使用
RadionButtonList
使用数据库取值步骤:
(1)数据绑定

List<Nation> list = new NationData().Select();

方法1:

RadioButtonList1.DataSource = list;//数据源
RadioButtonList1.DataTextField = "NationName";//显示值
RadioButtonList1.DataValueField = "NationCode";//实际值
RadioButtonList1.DataBind();

方法2:

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

(2)设置默认选中项

RadioButtonList1.SelectedIndex = 0;或
RadioButtonList1.SelectedValue = "N001";

(3)取值
添加一个按钮点击事件,事件中写:

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

四、布局
RepeatDirection:项的布局方式 Vertical 纵向 Horizontal:横向
RepeatColumns:规定项的列数
RepeatLayout:项的布局方式 Table Flow (UnorderedList:无序列表 OrderedList:有序列表 前两种属性无效)
2.复选按钮
HTML编码方式:

<input type="checkbox" name="" checked="checked"/>

Webform:
CheckBox 不建议使用
CheckBoxList 
使用数据库取值步骤:
(1)数据绑定

遍历数据集合,ListItem

 foreach (Nation n in list)
{
ListItem li = new ListItem(n.NationName, n.NationCode);
CheckBoxList1.Items.Add(li);
}

(2)设置默认选中项
在数据添加的时候进行判断,设置Selected属性

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 + "|";
}
}

四、布局
RepeatDirection:项的布局方式 Vertical 纵向 Horizontal:横向
RepeatColumns:规定项的列数
RepeatLayout:项的布局方式 Table Flow (UnorderedList:无序列表 OrderedList:有序列表 前两种属性无效)
3.下拉列表
HTML编码方式:

<select name="" id="" size=""   multiple="multiple">
<option></option>
<option></option>
</select>

(1)当它为一行可选菜单时:
Webform中使用DropDownList
使用数据库取值步骤与RadionButtonList相同,只是没有布局
(2)当它为列表时
Webform使用ListBox按钮,在属性中可选择单选还是多选
使用数据库取值步骤与CheckBoxList 相同,只是没有布局

Webform(简单控件、复合控件)的更多相关文章

  1. WebForm简单控件,复合控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 __________________ ...

  2. WebForm 简单控件、复合控件

    简单控件: Label:被编译成span 样式表里设置lable的高度:  display:inline-block; Text  --文本 ForeColor  --字体颜色 Visible  -- ...

  3. webform简单控件

    表单元素: 文本类: text password textarea hidden text,password,textarea实现控件:textbox   textmode属性选择password或m ...

  4. 2017年12月17日 ASP.NET 12个表单元素&&简单控件/复合控件

    12个表单元素可以分为三大类 第一类:文本类 <input type = "text" /> //普通文本框 <input type = "passwo ...

  5. webform 简单控件

    html中12个表单元素添加runat="server"后称为控件 Lable 编译之后是 <span></span> 属性:CssClass  编译成 c ...

  6. WebForm 【简单控件】【表单元素】

    一.HTML 表单元素复习 (1)文本类 文本框:<input type="text" name="" id="" value=&qu ...

  7. 【2017-05-18】WebForm的Repeater控件和一些简单控件

    一.Repeater控件 1. <%@ %> - 这里面写一些声明和引用的 <%  %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <% ...

  8. 【2017-05-18】WebForm的Repeater控件及简单控件

    <%@ %> - 这里面写一些声明和引用的 <%  %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <%# Eval("属性名 ...

  9. WebForm 常用控件

    一.简单控件 1.Label(作用:显示文字) Web中: <asp:Label ID="Label1" runat="server" Text=&quo ...

随机推荐

  1. C primer plus 练习题 第三章

    5. #include <stdio.h> int main() { float you_sec; printf("请输入你的年龄:"); scanf("%f ...

  2. SZ,RZ传送文件

    linux 和window之间通过xshell的命令 SZ,RZ传送文件:

  3. ODAC(V9.5.15) 学习笔记(十七)主从模式

    主从模式(Master/Detail mode)是指建立主表和从表关系的多个数据集集合模式. 1. 关系设置 要设置主从模式,必须有一个主表数据集(TDataSet)和一个从表数据集(TDataSet ...

  4. ADO.NET 3.5高级编程:应用LINQ&Entity Framework

    http://item.jd.com/10080604.html 第1部分 ADO.NET3.5概览第1章 使用ADO.NET3.5提供的新方法访问数据1.1 语言集成查询LINO1.1.1 LIQ  ...

  5. ASP.NET MVC 4 Web编程

    http://spu.jd.com/11309606.html 第1章 入门第2章 控制器第3章 视图第4章 模型第5章 表单和HTML辅助方法第6章 数据注解和验证第7章 成员资格.授权和安全性第8 ...

  6. 事务复制中的snapshot

        Snapshot agent读取article的信息,将article的内容和脚本放置到snapshot文件夹中: 接下来distribution agent会读取这些快照文件,传输到订阅,完 ...

  7. java中String byte HexString的转换

    原文:http://blog.sina.com.cn/s/blog_62e9ec530101ebv6.html HexString——>byte public static byte[] hex ...

  8. 2014 网选 5011 Game(Nim游戏,数学题)

    /* 题意:Nim游戏! 思路:通过异或,判断将n个数表示成二进制的形式之后,是否对应位的数字1 的个数是偶数! */ #include<iostream> using namespace ...

  9. 关于JavaScript中apply与call的用法意义及区别

    JavaScript中有一个call和apply方法,其作用基本相同,但也有略微的区别. 先来看看JS手册中对call的解释: call 方法调用一个对象的一个方法,以另一个对象替换当前对象. cal ...

  10. iOS-验证码倒计时60秒

    一. 要求 1.点击获取验证码按钮,60秒倒计时,按钮变成不可点击状态,按钮文字变成倒计时的秒数. 2.当倒计时为0的时候,释放掉定时器NSTimer,按钮变成可以点击状态,按钮文字变成"获 ...