zoukankan      html  css  js  c++  java
  • 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"]%> 

  • 相关阅读:
    机器学习之线性回归
    Anaconda使用
    Pycharm使用总结
    Mysql使用小tips
    技术转型与考研总结
    C语言的学习
    python 使用小结
    RedHat Linux 忘记密码
    设计模式之单例模式
    Java 读写Properties配置文件
  • 原文地址:https://www.cnblogs.com/jacktu/p/575617.html
Copyright © 2011-2022 走看看