Hopes

Start Here..

 

ASP.Net中的关于数据绑定

ASP.Net中的关于数据绑定

1. 绑定标签 <%# …… %> 可绑定标签属性值,表达式,方法的结果及数据源等。

a. 绑定属性之label的Text属性值 :

<asp: label1 ID="labtxt" Text="<%# DataTime.Now.ToShortString() %>" >

this.label1.DataBind();***************后台代码千万不能少

b.绑定变量

后台代码类中定义一变量 protected Color bgcolor=Color.FromA#b48cd2;

前台 <asp: label1 ID="labtxt" BackColor="<%# bgcolor %>" runat="server">

this.labtxt.DataBind();

c.绑定常量

后台 protected int a=15;

protected int b=10;

<td> a+b=<%# a+b %> <td>

this.DataBind();

d.绑定 方法

在后面写个方法 protected string GetDate(){……}

在前台 <td> 今天:<%# GetData() %> </td>

this.DataBind();

e.绑定 数组集合

Protected string[] strarray={"acb","def","xyz"};

< asp: DropDownList DataSource="<%# strarray %>" >

this.DataBind();

ASP.Net绑定数据源

1.使用DropDownList手动绑定数据源

public void GetBinds()

{

DataTable tb= GetTable(……);

this.DropDownList.DataSource=tb;

this.DropDownList.DataTextField="类别"; //可见值

this.DropDownList.DataValueField="ID" //隐藏值

}

调用该 方法后记的 加上 this.DataBind();



2. 篇历的 ChickBoxList

for (int i=0; i<checkboxlist1.Items.Count; i++)
{
if (checkboxlist1.Items[i].Selected)
{
Label1.Text += checkboxlist1.Items[i].Text + "<br />";
}
}

posted on 2012-09-16 14:02 ** 阅读(130) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

公告

你好!

常用链接

留言簿(2)

随笔档案

文章分类

文章档案

新闻档案

相册

收藏夹

C#学习

友情链接

搜索

最新评论

阅读排行榜

评论排行榜