webform控件
簡單控件:
1、Label
會被編譯成span標簽
屬性:
Text:文本內容
CssClass:CSS樣式
<asp:Label ID="Label1" runat="server" Text="1234" CssClass="aaa"></asp:Label>Enlabled:是否可用
Visible:是否可見
2、Literal
空的,C#會把里面的Text內容直接作為網頁代碼傳過去,比如Text里面寫上<input type="button" />會直接在網頁中插入一個按鈕
屬性:
Text:內容
<asp:Literal ID="Literal1" runat="server" Text="2016-12-29"></asp:Literal> <asp:Literal ID="Literal1" runat="server" Text="<script>alert('2016年12月29日')</script>"></asp:Literal>alert:彈出
3、TextBox
文本框
屬性:
TextMode - text模式
1、默認 SingleLine - 單行文本框,編譯后為 type="text"
2、Password - 密碼框,編譯后為 type="password"
3、MultiLine - 文字域,編譯后為 <textarea></textarea>
在設計界面中 textmode 屬性有多個,只用前三個
maxlength:最大長度,在文本域?<textarea></textarea> 中不起作用
readonly:只讀屬性
4、HiddenField
隱藏域
5、Button
提交按鈕(控件中沒有對應的普通按鈕和重置按鈕)
? ? ?imagebutton - image 提交圖片
? ? ?linkbutton - 超鏈接模樣的按鈕,僅控件如此
? ? ?button、reset - 沒有控件對應
button屬性:
?OnClientClick - 在客戶端OnClick上執行的客戶端腳本
?
復合控件:
1、RadioButton 和 RadioButtonList
單選按鈕
? ? ?大多情況下使用后者
前者:
<asp:RadioButton ID="RadioButton1" runat="server" Text="男" /> <asp:RadioButton ID="RadioButton2" runat="server" Text="女" />屬性:
GroupName - 分組,用于選擇
<asp:RadioButton ID="RadioButton1" runat="server" Text="男" GroupName="sex" /> <asp:RadioButton ID="RadioButton2" runat="server" Text="女" GroupName="sex" />RadioButtonList - 單選按鈕組
綁定數據:
RadioButtonList1.DataSource = 泛型集合;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataBind(); - 必須要有
設置選中項:
按照索引選中:
RadioButtonList1.SelectedIndex = slist.Count - 1;
按照value值選中:
RadioButtonList1.SelectedValue = "002";
按照Text選中:
foreach (ListItem li in RadioButtonList1.Items)
{
if (li.Text == "周村")
{
li.Selected = true;
}
}
取出數據:
取出value值
Label1.Text = RadioButtonList1.SelectedValue;
取出Text值
Label1.Text = RadioButtonList1.SelectedItem.Text;
屬性:
RepeatDirection:橫向或豎向排列
RepeatLayout:編譯成表格、流式或者有序無序列表的樣式
2、CheckBox 和 CheckBoxList
復選按鈕
綁定數據源與設置單個選擇項同上,如果要設置多個選擇項,則需要遍歷
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Label1.Text += li.Text + ",";
}
}
3、DropDownList
下拉菜單
與單選按鈕列表類似
4、ListBox
多選框
與ChekckBoxList類似
屬性:
SelectionMode:設置是否可以多選
轉載于:https://www.cnblogs.com/jiuban2391/p/6237390.html
總結