基本的Web控件四
基本的Web控件用法二
ListBox控件
页面布局:
<div>
<h1>ListBox控件</h1>
学生列表:
<br/>
<asp:ListBox ID="ListBox1" runat="server" Width="100" Height="100" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged“AutoPostBack="true">
</asp:ListBox>
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br/>
</div>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//生成数据
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "王聪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "李宁", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "菡萏", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "青松", 100 });
//绑定到ListBox控件
this.ListBox1.DataSource = ds.Tables["stu"];
this.ListBox1.DataValueField = "stuNo";
this.ListBox1.DataTextField = "stuName";
this.ListBox1.DataBind();
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = "你选择的学生是:" + this.ListBox1.SelectedItem.Text.ToString();
}
DropDownList控件
页面布局:
<div>
<h1>DropDownList控件</h1>
学生列表:
<br/>
<asp:DropDownList ID="DropDownList1" Font-Size="Large" runat="server" AutoPostBack="true" Width="146px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br/>
<asp:Label ID="Label1" runat="server"></asp:Label>
<hr/>
<hr/>
</div>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//生成数据
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "王聪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "李宁", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "菡萏", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "青松", 100 });
//绑定到ListBox控件
this.DropDownList1.DataSource = ds.Tables["stu"];
this.DropDownList1.DataValueField = "stuNo";
this.DropDownList1.DataTextField = "stuName";
this.DropDownList1.DataBind();
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = "你选择的学生是:" + this.DropDownList1.SelectedItem.Text.ToString();
}
CheckBoxList控件
页面布局:
<div>
<h1>CheckBoxList控件</h1>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"
AutoPostBack="true" Width="180px">
</asp:CheckBoxList>
<br/>
<asp:Label ID="Label1" runat="server"></asp:Label>
<hr/>
<hr/>
</div>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//生成数据
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "王聪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "李宁", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "菡萏", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "青松", 100 });
//绑定到ListBox控件
this.CheckBoxList1.DataSource = ds.Tables["stu"];
this.CheckBoxList1.DataValueField = "stuNo";
this.CheckBoxList1.DataTextField = "stuName";
this.CheckBoxList1.DataBind();
}
}
RadioButtonList控件
页面布局:
<div>
<h1>RadioButtonList控件</h1>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="180px" AutoPostBack="true">
</asp:RadioButtonList>
<hr/>
<hr/
</div>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//生成数据
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "王聪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "李宁", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "菡萏", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "青松", 100 });
//绑定到ListBox控件
this.RadioButtonList1.DataSource = ds.Tables["stu"];
this.RadioButtonList1.DataValueField = "stuNo";
this.RadioButtonList1.DataTextField = "stuName";
this.RadioButtonList1.DataBind();
}
}
BulletedList控件
页面布局:
<div>
<h1>BulletedList控件</h1>
<asp:BulletedList ID="BulletedList1" runat="server" BulletStyle="Square">
</asp:BulletedList>
<hr/>
<hr/>
</div>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//生成数据
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "王聪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "李宁", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "菡萏", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "青松", 100 });
//绑定到ListBox控件
this.BulletedList1.DataSource = ds.Tables["stu"];
this.BulletedList1.DataValueField = "stuNo";
this.BulletedList1.DataTextField = "stuName";
this.BulletedList1.DataBind();
}
}
Table控件
页面布局:
<div>
<h1>Table控件</h1>
动态操作表控件<br/>
行数:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
列数:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br/>
<asp:Button ID="Button1" runat="server" Text="动态生成" OnClick="Button1_Click" />
<br/>
<asp:Table ID="Table1" runat="server" Caption="动态操作表控件" CellPadding="1" CellSpacing="1" GridLines="Both"> </asp:Table>
<hr/>
<hr/>
</div>
后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
int rowNum = 0; //定义行数
int rowCount = 0; //定义当前行数
int cellNum = 0; //定义列数
int cellCount = 0; //定义当前列数 //获取用户输入的行数和列数
try
{
rowNum = int.Parse(TextBox1.Text);
cellNum = int.Parse(TextBox2.Text);
}
catch
{
rowCount = 1;
cellCount = 1;
}
for (rowCount = 1; rowCount <= rowNum; rowCount++)
{
//为Table1表添加一行
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow); for (cellCount = 1; cellCount <= cellNum; cellCount++)
{
//创建单元格并添加到表中
TableCell tCell = new TableCell();
tRow.Cells.Add(tCell); //添加一个用来包含文本的Literal类,作为控件添加到单元格中
tCell.Controls.Add(new LiteralControl("当前位置:")); //创建一个Hyperlink控件并把它添加到单元格中
System.Web.UI.WebControls.HyperLink h = new HyperLink();
h.Text = rowCount + ":" + cellCount;
h.NavigateUrl = "http://www.microsoft.com/net";
tCell.Controls.Add(h);
}
}
}
原文链接:
http://blog.csdn.net/spilledlight/article/details/48712381
基本的Web控件四的更多相关文章
- 基本的Web控件三
基本的Web控件用法一 ListBox控件 页面布局: <div> <h1>ListBox控件</h1> 学生列表: <br/> <asp:Lis ...
- 2015.2.16 关于delphi web控件打开新网页时弹出关闭页面(js代码)出错的解决办法研究
参考网址1:http://www.csharpwin.com/csharpspace/2360.shtml...参考网址2:http://www.oschina.net/question/234345 ...
- 033. asp.netWeb用户控件之二将页面转换成web控件和使用Web控件显示热点新闻
访问Web用户控件的属性 ASP.NET提供的各种服务器控件都有其自身的属性和方法,程序开发人员可以灵活地使用服务器控件中的属性和方法开发程序.在用户控件中,程序开发人员也可以自行定义各种属性和方法, ...
- [MFC] MFC 打开HTML资源(用ID版,也可加载到自己的web控件上)
@ ^ @:如果是加载到web控件上,就把注释掉的解除注释(改为web控件点后面的函数),把下一句注释 BOOL Button::LoadFromResource(UINT nRes){//打开网页加 ...
- 译:c#生成条码的web控件
译文:http://www.codeproject.com/Tips/846860/Csharp-Barcode-Generator-Web-Control 在asp.net的web页用c#的web控 ...
- Javascript语法去控制Web控件的Enabled属性
Web控件当使用Enabled属性时,它生成html之后会变成了disabled了.我们为了能够在javascript去控制控件的禁用与启用,得从这个disabled入手.如:
- Web控件文本框Reset的功能
在前一篇中<怎样实现Web控件文本框Reset的功能>http://www.cnblogs.com/insus/p/4120889.html Insus.NET只实现了文本框的功能.单个或 ...
- 怎样实现Web控件文本框Reset的功能
在ASP.NET开发过程序,在数据插入之后,文本框TextBox控件需要Reset.如果只有一两个文件框也许没有什么问题,如果网页上有很多文本框,你就会有点问题了.再加上某一情形,一些文本框是有默认值 ...
- 基本的Web控件一
ASP.NET提供了与HTML元素相对应的基本Web控件,ASP.NET提供的基本的Web控件如下: 基本的Web控件 对应的HTML元素 Label ----------------- ...
随机推荐
- highstock实现股票分时
highchart学习网站 www.highcharts.com http://www.hcharts.cn/docs/index.php http://www.hcharts.cn/api/high ...
- Redis中7种集合类型应用场景&redis常用命令
Redis常用数据类型 Redis最为常用的数据类型主要有以下五种: String Hash List Set Sorted set 在具体描述这几种数据类型之前,我们先通过一张图了解下Redis内部 ...
- JAVA坏境变量中的JAVA_HOME path classpath 的设置与作用。
在把jdk安装到计算机中之后,我们来进行设置使java环境能够使用. 首先右键点我的电脑.打开属性.然后选择“高级”里面的“环境变量”,在新的打开界面中的系统变量需要设置三个属性“JAVA_HOME” ...
- Android NFC开发概述
NFC手机相比普通手机来说,有以下3个附加功能: 1.可以当成POS机来用,也就是“读取”模式 2.可以当成一张卡来刷,也就是NFC技术最核心的移动支付功能 3.可以像蓝牙.Wi-Fi一样做点 ...
- 官网下载jdk
http://www.oracle.com/technetwork/java/javase/downloads/index.html 第一步: 第二步:默认是显示最新版本的,如果需要其他版本的,拖到最 ...
- CodeForces 602E【概率DP】【树状数组优化】
题意:有n个人进行m次比赛,每次比赛有一个排名,最后的排名是把所有排名都加起来然后找到比自己的分数绝对小的人数加一就是最终排名. 给了其中一个人的所有比赛的名次.求这个人最终排名的期望. 思路: 渣渣 ...
- nyoj 103 A + B problem II
点击打开链接 A+B Problem II 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. G ...
- NYOJ-228 士兵杀敌5
士兵杀敌(五) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 南将军麾下有百万精兵,现已知共有M个士兵,编号为0~M,每次有任务的时候,总会有一批编号连在一起人请战(编 ...
- Hive分布式的数据仓库
1.hive介绍 hive是一个数据仓库的解决方案,它的数据存储依赖于HDFS,数据结算依赖于MR,也就是说,hive就是一个在数据仓库的服务,它只需要安装到一台普通的PC上即可,仅仅对外提供SQL服 ...
- ASP.net 探针
<%@ Page Language="JScript" ContentType="text/html" ResponseEncoding="gb ...