会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
着迷Linux
菲一打
将数据库中字符型的数据格式化为货币型数据输出
<
%@ Page Language
=
"
VB
"
AutoEventWireup
=
"
True
"
Debug
=
"
true
"
%
>
<
%@ Import
Namespace =
Namespace
=
"
System.Data
"
%
>
<
%@ Import
Namespace =
Namespace
=
"
System.Data.OleDb
"
%
>
<
script runat
=
"
server
"
>
Dim
MyConnection
as
OleDbConnection
Sub Page_Load()
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
MyConnection
=
New
OleDbConnection(
"
Provider=Microsoft.Jet.OLEDB.4.0; Data Source =
"
+
Server.MapPath(
"
.
"
)
+
"
/db/otherdata.mdb
"
)
If
Not
IsPostBack
Then
BindGrid()
End
If
End Sub
Sub MyDataGrid_Page()
Sub
MyDataGrid_Page(sender
as
Object
, e
As
DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex
=
e.NewPageIndex
BindGrid()
End Sub
Sub BindGrid()
Sub
BindGrid()
Dim
MyCommand
As
OleDbDataAdapter
=
new
OleDbDataAdapter(
"
Select * FROM info
"
, MyConnection)
Dim
DS
As
DataSet
=
new
DataSet()
MyCommand.Fill(DS,
"
info
"
)
MyDataGrid.DataSource
=
DS.Tables(
"
info
"
).DefaultView
MyDataGrid.DataBind()
End Sub
Protected
Sub DataGrid_ItemDataBound()
Sub
DataGrid_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
DataGridItemEventArgs)
If
e.Item.ItemType
=
ListItemType.AlternatingItem
OrElse
e.Item.ItemType
=
ListItemType.Item
Then
If
Not
(e.Item.Cells(
2
).Text
=
"
"
)
Then
If
Convert.ToDouble(e.Item.Cells(
2
).Text)
>
Convert.ToDouble(
100000
)
Then
e.Item.BackColor
=
System.Drawing.Color.LightBlue
e.Item.ForeColor
=
System.Drawing.Color.SandyBrown
End
If
e.Item.Cells(
2
).Text
=
String
.
Format
(
"
{0:c}
"
, Convert.ToDouble(e.Item.Cells(
2
).Text))
Else
e.Item.Cells(
2
).Text
=
String
.
Format
(
"
{0}
"
,
"
No Sales
"
)
e.Item.Cells(
2
).ForeColor
=
System.Drawing.Color.red
End
If
End
If
End Sub
</
script
>
<
FORM id
=
"
Form1
"
method
=
"
post
"
runat
=
"
server
"
>
<
ASP:DATAGRID id
=
"
MyDataGrid
"
width
=
"
200
"
runat
=
"
server
"
autogeneratecolumns
=
"
False
"
showfooter
=
"
False"
BACKCOLOR
=
"
#E0E0E0"
OnItemDataBound
=
"
DataGrid_ItemDataBound
"
>
<
ALTERNATINGITEMSTYLE BACKCOLOR
=
"
Silver
"
></
ALTERNATINGITEMSTYLE
>
<
HEADERSTYLE FONT
-
BOLD
=
"
True
"
FORECOLOR
=
"
White
"
BACKCOLOR
=
"
Black
"
></
HEADERSTYLE
>
<
COLUMNS
>
<
asp:BoundColumn DataField
=
"
ProductID
"
HeaderText
=
"
Product ID
"
>
<
ITEMSTYLE HORIZONTALALIGN
=
"
Left
"
></
ITEMSTYLE
>
</
asp:BoundColumn
>
<
asp:BoundColumn DataField
=
"
ProductName
"
HeaderText
=
"
Product Name
"
>
<
ITEMSTYLE HORIZONTALALIGN
=
"
Left
"
></
ITEMSTYLE
>
</
asp:BoundColumn
>
<
asp:BoundColumn DataField
=
"
CategoryName
"
HeaderText
=
"
Category
"
>
<
ITEMSTYLE HORIZONTALALIGN
=
"
Right
"
></
ITEMSTYLE
>
</
asp:BoundColumn
>
</
COLUMNS
>
</
ASP:DATAGRID
>
</
FORM
>
发表于
2005-03-12 10:47
菲一打
阅读(
730
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告
导航
博客园
首页
新随笔
新文章
联系
订阅
管理