zoukankan
html css js c++ java
如何使用 DataBinder.Eval(Container.DataItem,"num","{0:p}") 对DataList 进行数据绑定
如何使用 DataBinder.Eval(Container.DataItem,"num","{0:p}") 对DataList 进行数据绑定
前台页面代码:
1
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
DataContainer.aspx.cs
"
Inherits
=
"
test_DataBind_DataContainer
"
%>
2
<%
@ Import Namespace
=
"
System.Data
"
%>
3
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
4
5
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
6
<
head
runat
="server"
>
7
<
title
>
无标题页
</
title
>
8
</
head
>
9
<
body
>
10
<
form
id
="form1"
runat
="server"
>
11
<
div
>
12
<
asp:DataList
ID
="DataList1"
runat
="server"
>
13
<
ItemTemplate
>
14
数字:
<%
# ((DataRowView)Container.DataItem)[
"
num
"
]
%>
15
平方:
<%
# (
int
)((DataRowView)Container.DataItem)[
"
num
"
]
*
(
int
)((DataRowView)Container.DataItem)[
"
num
"
]
%>
16
货币:
<%
# DataBinder.Eval(Container.DataItem,
"
num
"
,
"
{0:p}
"
)
%>
17
</
ItemTemplate
>
18
</
asp:DataList
></
div
>
19
</
form
>
20
</
body
>
21
</
html
>
22
后台页面代码:
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Collections;
5
using
System.Web;
6
using
System.Web.Security;
7
using
System.Web.UI;
8
using
System.Web.UI.WebControls;
9
using
System.Web.UI.WebControls.WebParts;
10
using
System.Web.UI.HtmlControls;
11
12
public
partial
class
test_DataBind_DataContainer : System.Web.UI.Page
13
{
14
protected
void
Page_Load(
object
sender, EventArgs e)
15
{
16
if
(
!
this
.IsPostBack)
17
{
18
DataTable dt
=
new
DataTable();
//
先定义一个数据表对象.
19
dt.Columns.Add(
"
num
"
,
typeof
(
int
));
//
添加列 参数:字段名称,数据类型
20
for
(
int
i
=
0
; i
<
10
;i
++
)
21
{
22
DataRow dr
=
dt.NewRow();
//
添加行,注意写法: dt.NewRow();
23
dr[
0
]
=
i;
24
dt.Rows.Add(dr);
//
将行添加到项目中.
25
}
26
this
.DataList1.DataSource
=
dt;
27
this
.DataList1.DataBind();
28
}
29
}
30
}
31
查看全文
相关阅读:
sockaddr与sockaddr_in,sockaddr_un结构体详细讲解
busybox程序连接 ln怎么回事?怎样实现的
有线网卡与无线网卡同时使用
"$(@:_config=)"
C#中Global文件
Win7 IIS7 HTTP 错误 404.2 Not Found解决方法
C#中的日期处理函数
js字母大小写转换
asp.net发布到IIS中出现错误:处理程序“PageHandlerFactoryIntegrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
sql server在存储过程中使用游标和事务
原文地址:https://www.cnblogs.com/gfwei/p/538966.html
最新文章
[HTA] HTML应用程序
[JS] 判断IE6和IE7
[D3D] DirectX SDK 2006学习笔记3——索引缓冲
[D3D] Alpha闪烁效果
[D3D] DirectX SDK 2006学习笔记5——动画和矩阵变换
[JS] 清空file控件(兼容IE,火狐)
[D3D] DirectX SDK 2006学习笔记4——纹理
[PHP] var_export 与 var_dump的不同
【WP7】TextBlock长文本显示
【WP7】一键开关
热门文章
【Emgu】一起学EmguCV(一)配置与使用
【WP7】WP7.8使用WP8的磁贴
【C#】反射机制
【WP7】Sqlite使用
【WP7】SQLite数据库导入使用
【C#】马赛克的艺术
【WP7】使用联系人和约会数据
【Emgu】一起学EmguCV(二)Image和Matrix的使用
ERROR: "This virtual machine appears to be in use"
你需要的不是重构,而是理清业务逻辑
Copyright © 2011-2022 走看看