博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

数据绑定

Posted on 2006-10-24 00:32  孤峰皓月  阅读(294)  评论(0编辑  收藏  举报
查看数据绑定基本知识:http://chs.gotdotnet.com/quickstart/aspplus/doc/webdatabinding.aspx


1:简单绑定(绑定到另一个控件的属性上)
textbox 中的changed事件中:  Page.DataBind();
在要绑定的控件text 属性中:<asp:label  name=label1 runat=server text=<%# textBox1.Text %>/>


2.集合绑定: 比如以前学的 DropDowList 的 DataValueFile,DataTextFile 等,
   <asp:listbox id="listbox1" runat="server" DataSource="<%# Array%>">
   其中: <%# Array%>   比如里面的 Array 是对象名或数组.
   这种绑定方法通过编程来实现.

3.表达式绑定<%# (customer.FirstName +"" + customer.LastName )%>    对象名.属性

4.方法结果 <%#  GetBalance(custID) %>   绑定 方法返回的结果

DataBinder.Eval() 方法  命名容器 手工绑定
<%# DataBinder.Eval(Container.Dataltem,"max_lvl","{0:c}") %>
参数:
数据项的命名容器,数据字段名,格式字符串.