SalesAmount字段类型为字符型.
<%@ 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
e.Item.Cells(1).ToolTip = e.Item.Cells(6).Text
If Convert.ToInt32(CType((e.Item.Cells(4).Controls(0)), LinkButton).Text) = 0 Then
Dim wcTemp As WebControl = CType(e.Item.Cells(4).Controls(0), WebControl)
wcTemp.Enabled = False
Else
If Convert.ToInt32(CType((e.Item.Cells(4).Controls(0)), LinkButton).Text) < 10 Then
e.Item.Cells(4).ForeColor = System.Drawing.Color.Red
e.Item.Cells(4).Font.Bold = True
End If
End If
If Not (e.Item.Cells(5).Text = " ") Then
If Convert.ToDouble(e.Item.Cells(5).Text) > Convert.ToDouble(100000) Then
e.Item.BackColor = System.Drawing.Color.LightBlue
e.Item.ForeColor = System.Drawing.Color.SandyBrown
End If
e.Item.Cells(5).Text = String.Format("{0:c}", Convert.ToDouble(e.Item.Cells(5).Text))
Else
e.Item.Cells(5).Text = String.Format("{0}", "No Sales")
e.Item.Cells(5).ForeColor = System.Drawing.Color.red
End If
End If
End Sub
</script>
<FORM id="Form1" method="post" runat="server">
<ASP:DATAGRID id="MyDataGrid"
width="90%"
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>
<asp:BoundColumn DataField="SubCategoryName" HeaderText="Sub Category">
<ITEMSTYLE HORIZONTALALIGN="Right"></ITEMSTYLE>
</asp:BoundColumn>
<asp:ButtonColumn DataTextField="NoOfSales" HeaderText="Sales Count" CommandName="CountOnClick">
<ITEMSTYLE HORIZONTALALIGN="Right"></ITEMSTYLE>
</asp:ButtonColumn>
<asp:BoundColumn DataField="SalesAmount" HeaderText="Sales Amount" >
<ITEMSTYLE HORIZONTALALIGN="Right"></ITEMSTYLE>
</asp:BoundColumn>
<asp:BoundColumn DataField="ProductModelName" Visible=False ></asp:BoundColumn>
</COLUMNS>
</ASP:DATAGRID>
</FORM>
发表于
2005-03-12 10:28
菲一打
阅读( 267)
评论()
收藏
举报
|