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"]%> 

  • 相关阅读:
    005 Stream的创建
    006 虚拟主机
    002 nginx的进程模型
    001 胡说八道
    001 nginx的简介和安装
    004 docker配置国内镜像站
    012 SSH
    发放失败,此请求可能存在风险,已被微信拦截【未解决】
    项目使用Nuget,然后SVN checkout后显示缺少引用
    使用存储过程非常慢,但是直接执行SQL很快
  • 原文地址:https://www.cnblogs.com/jacktu/p/575617.html
Copyright © 2011-2022 走看看