您的位置:首页 > 编程语言 > ASP

ASP.Net中的关于数据绑定

2012-04-16 09:50 357 查看
1. 绑定标签 <%# …… %> 可绑定标签属性值,表达式,方法的结果及数据源等。

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

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

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

b.绑定变量

后台代码类中定义一变量 protected Color bgcolor=Color.FromArgb(180,140,210);

前台 <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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: