前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Asp.Net第二章服务器端控件

Asp.Net第二章服务器端控件

作者头像
用户9184480
发布2024-12-19 09:31:24
发布2024-12-19 09:31:24
5500
代码可运行
举报
文章被收录于专栏:云计算linux云计算linux
运行总次数:0
代码可运行

服务器端控件

主要有:Label、TextBox、Button、RadioButton、CheckBox、RadioButtonList、CheckBoxList、HyperLink控件。

控件

Label、TextBox

代码语言:javascript
代码运行次数:0
复制
<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

代码语言:javascript
代码运行次数:0
复制
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

代码语言:javascript
代码运行次数:0
复制
if (DropDownList1.SelectedItem.Text != "请选择所在城市")
                 Response.Write("您所在的城市为:"+DropDownList1.SelectedItem.Text);
             else
                 Response.Write("请选择所在城市");

LIstBox控件,是将DropDowList的内容,可以一次性显示出来。DropDownList下拉效果。

代码语言:javascript
代码运行次数:0
复制
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

代码语言:javascript
代码运行次数:0
复制
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,属性是Selected
                 if (CheckBoxList1.Items[i].Selected) {
                     hobby += CheckBoxList1.Items[i].Text;
                 }
             }


             String str = String.Format(@"您的期待岗位是'{0}',爱好是'{1}'", msg,hobby);
             Response.Write(str);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-02-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 服务器端控件
  • 控件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档