ASP.Net中的关于数据绑定
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();