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
查看全文
相关阅读:
Android MVP框架实现过程
bga-banner-引导页滑动第三方控件
好的习惯是成功的一半之开发
Java基础复习之String字符串format处理
ButterKnife--View注入框架的使用
div阴影
JavaScript函数的4种调用方法详解
JavaScript的三种对话框是通过调用window对象的三个方法alert(),confirm()和prompt()
HTML文字闪烁
HTML文本框样式大全
原文地址:https://www.cnblogs.com/gfwei/p/538966.html
最新文章
如何查看MySQL的当前存储引擎?
PHP图片上传程序(完整版)
PHP5中PDO的简单使用
PHP文件缓存
My Site Cleanup Job
form 认证 读取
sharepoint 2013工具
内网升级工作初步计划和协助
sharepoint 2013 升级要求
安装OWA2013
热门文章
cannot connect cube with sharepoint dashboard designer
sharepoint 通过数据库擅长列表项
图表控件
debug时 出现source not found
SQL 连接查询
mysql添加外键时 [Err] 1005
Android 4.4-7.0 apk的更新换代策略
一行代码使Android状态栏变沉浸式透明化
安卓App热补丁动态修复技术
关于客户端设计之数据分类和存储 的思考
Copyright © 2011-2022 走看看