Asp.Net第二章服务器端控件
生活随笔
收集整理的這篇文章主要介紹了
Asp.Net第二章服务器端控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
服務器端控件
主要有:Label、TextBox、Button、RadioButton、CheckBox、RadioButtonList、CheckBoxList、HyperLink控件。
控件
Label、TextBox
?<form id="form1" runat="server"><div><!--html控件,html服務器端控件,asp.net服務端控件--><input type="text" name="uname1" /><br /><input type="text" name="uname1" runat="server"/><br /><asp:Label ID="lbl" Text="我是服務器端控件" runat="server" /></div></form>TextBox:設置密碼或多行
使用TextMode屬性; SingleLine:單行 Password:密碼;Multiline:多行;
AutoPostBack:自動提交;
?
RadioButton RadioButtonList
GroupName:設置這個
Text Value
? String msg = "";?if (RadioButton1.Checked)msg += RadioButton1.Text;if (RadioButton2.Checked)msg += RadioButton2.Text;//asxh:request response?msg+=",直轄市:"+RadioButtonList1.SelectedItem.Text+",競爭力值:"+RadioButtonList1.SelectedValue;Response.Write("性別:"+msg);?
DropDowList
? if (DropDownList1.SelectedItem.Text != "請選擇所在城市")Response.Write("您所在的城市為:"+DropDownList1.SelectedItem.Text);elseResponse.Write("請選擇所在城市");LIstBox控件,是將DropDowList的內容,可以一次性顯示出來。DropDownList下拉效果。
?for (int i = srcList.Items.Count - 1; i >= 0; i--) {//先獲取源頭List的Items[i]項//ListItem item = srcList.Items[i];//if (item.Selected) {// ? destList.Items.Add(item);// ? srcList.Items.Remove(item);//}//多種方式的實現ListItem item=srcList.SelectedItem;if (item!=null){destList.Items.Add(srcList.SelectedItem);srcList.Items.Remove(srcList.SelectedItem);}}?
CheckBox、CheckBoxList
? string msg = " ",hobby="";?if (CheckBox1.Checked)msg += CheckBox1.Text;if (CheckBox2.Checked)msg += CheckBox2.Text;if (CheckBox3.Checked)msg += CheckBox3.Text;if (CheckBox4.Checked)msg += CheckBox4.Text;if (CheckBox5.Checked)msg += CheckBox5.Text;//針對CheckBoxList做一個循環for (int i = 0; i < CheckBoxList1.Items.Count; i++) { //其中每一項是一個Item,屬性是Selectedif (CheckBoxList1.Items[i].Selected) {hobby += CheckBoxList1.Items[i].Text;}}??String str = String.Format(@"您的期待崗位是'{0}',愛好是'{1}'", msg,hobby);Response.Write(str);?
?
總結
以上是生活随笔為你收集整理的Asp.Net第二章服务器端控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Asp.Net第一章入门之后台处理程序
- 下一篇: ES6前端就业课第三课之class