1.简单绑定:
绑定语法:<%#字段名或属性名%>
例如:
页面(前台):
<body style=‘<%#bodystyle%>’>…</body>
代码(后台):
protected string bodystyle;
protected void Page_Load(object sender, EventArgs e) {
bodystyle = "background-color:#ff0000";
2.复杂绑定:
手动添加:
this.DropDownList1.Items.Add(new ListItem("红色", "red"));
this.DataBind();
从数据库提取:
this.DropDownList1.DataSource=ds.Tables[0];
this.DropDownList1.DataTextField="name";
this.DropDownList1.DataValueField="id";
this.DropDownList1.DataBind();