asp.net各种数据绑定方式

         绑定的属性必须是public
        绑定到简单属性:<%#UserName%>
        绑定到集合:<asp:ListBox id="ListBox1" datasource='<%# myArray%>' runat="server">
        绑定到表达式:<%#(class1.property1.ToString() + "," + class1.property2.ToString())%>
        绑定到方法返回值:<%# GetSafestring(str) %>
        绑定到Hashtable:<%# ((DictionaryEntry)Container.DataItem).Key%>
        绑定到ArrayList:<%#Container.DataItem %>
        若数组里里放的是对象则可能要进行必要的转换后再绑定如:
        <%#((对象类型)Container.DataItem).属性%>
       
         绑定到DataView,DataTable,DataSet:
        <%#((DataRowView)Container.DataItem)["字段名"]%>或
        <%#((DataRowView)Container.DataItem).Rows[0]["字段名"]%>
        要格式化则(这种方式效率比较低,原因是使用到了反射机制):
        <%#string.Format("格式",((DataRowView)Container.DataItem)["字段名"])%>
        <%#DataBinder.Eval(Container.DataItem,"字段名","格式")%>

        绑定到DataReader:
        <%#((IDataReader)Container.DataItem).字段名%>

       <%# ((DataRowView)Container.DataItem)["xxxx"]%> 

原文地址:https://www.cnblogs.com/jacktu/p/575617.html