数据的绑定

来源:互联网 发布:vscode在插件 编辑:程序博客网 时间:2024/06/15 09:56

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();

原创粉丝点击