ASP.NET DataBinder.Eval()
来源:互联网 发布:我的世界0.15js大全 编辑:程序博客网 时间:2024/04/29 19:20
在绑定数据时经常会用到这个句程序:<%# DataBinder.Eval(Container.DataItem,"xxxx")%>或者<%# DataBinder.Eval(Container,"DataItem.xxxx")%>
微软这种方法的效率更高,但我不常用,我习惯了上一种。
<%# ((DataRowView)Container.DataItem)["xxxx"]%> 用这种方法首先要在前台页面导入名称空间System.Data,否则会生成错误信息。
<%@ Import namespace="System.Data" %>
DataBinder.Eval()可以梆定方法,Text='<%# PBnumber(DataBinder.Eval(Container.DataItem,"photoBookID")) %>后台代码:
protected string PBnumber(object PBid)
{
string str = "[ " + Convert.ToString(PBc.GetInPbkPnum((int)PBid)) + " ] 张";
return str;
}
DataBinder.Eval还可以判断选择,如以性别为例:
<asp:TemplateColumn HeaderText="性别">
<ItemTemplate>
<%# DGFormatSex(Convert.ToString(DataBinder.Eval(Container.DataItem,"xb"))) %>
</ItemTemplate>
</asp:TemplateColumn>
cs里定义DGFormatSex方法
protected string DGFormatSex(string xb)
{
if(xb == "1")
return "男";
else
return "女";
}
DataBinder.Eval用法范例
//显示二位小数
//<%# DataBinder.Eval(Container.DataItem, "UnitPrice", "${0:F2}") %>
//{0:G}代表显示True或False
//<ItemTemplate>
// <asp:Image Width="12" Height="12" Border="0" runat="server"
// AlternateText='<%# DataBinder.Eval(Container.DataItem, "Discontinued", "{0:G}") %>'
// ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Discontinued", "~/images/{0:G}.gif") %>' />
// </ItemTemplate>
//转换类型
((string)DataBinder.Eval(Container, "DataItem.P_SHIP_TIME_SBM8")).Substring(4,4)
{0:d} 日期只显示年月日
{0:yyyy-mm-dd} 按格式显示年月日
{0:c} 货币样式
- ASP.NET DataBinder.Eval()
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- [ASP.NET]DataBinder.Eval用法
- Asp.net中DataBinder.Eval 用法
- [ASP.NET]DataBinder.Eval用法,文本绑定
- ASP.NET中的DataBinder.Eval用法
- ASP.NET中的DataBinder.Eval用法
- ASP.NET中的Eval()和DataBinder.Eval()方法
- 引用 ASP.NET中的Eval()和DataBinder.Eval()方法
- ASP.NET中的Eval()和DataBinder.Eval()方法
- ASP.NET中的Eval()和DataBinder.Eval()方法
- ASP.NET中的Eval()和DataBinder.Eval()方法
- ASP.NET中的Eval()和DataBinder.Eval()方法
- 再回首线程与进程的
- oracle 的procedure 中使用游标和数组的说明
- kmess安装
- 数据库优化方案
- Filter过滤器 温习
- ASP.NET DataBinder.Eval()
- 基于OSGI的Cache组件的实现
- css图片滤镜参考
- 侯捷演讲摘要
- VNC 恶补
- 据说这里不会吃空格
- 过滤器总结 转贴至 http://beauty9235.javaeye.com/blog/229651
- JBoss做成Redhat Linux的系统服务
- jsp 环境