0
首先,對我很好,因爲這是我第一次嘗試從我習慣的VBA標準中做出任何事情。ASP.NET(VB)Rowdatabound將所有數據視爲文本不是整數或小數
我有一個小報告互聯網網站設置,我有數據存儲在數據庫(SQL Server 10.50.40000),並存儲爲Int
/Varchar
/decimal (18,2)
。我已經使用Visual Web Dev 2010創建了一個網頁(VB)來訪問這些數據並進行顯示,但是由於某些原因,我無法對數據進行任何格式設置,因此我只能通過e.row.cells(COLUMNNUM).text
訪問數據,但是當我嘗試訪問數據時Parse
/cast
/CInt
/TryParse
該信息我得到一個錯誤,建議輸入數據不正確。
我已經搜索了至少20個不同版本的這個,但我無法找到任何有效的東西(90%的問題是C#和我不想(如果我可以幫助它))爲VB。
代碼隱藏(.aspx.vb):
Imports System.Drawing
Imports System.Data
Imports System.Data.SqlClient
Public Class FI7DayReport
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Dim testValue As String = e.Row.Cells(3).Text
Dim today, today1, today2, today3, today4, today5, today6, today7, today8, today9 As Date
Dim fiday As Integer
today = DateTime.Now.ToString("dd-MM-yy")
today1 = DateTime.Today.AddDays(+1).ToString("dd-MM-yy")
today2 = DateTime.Today.AddDays(+2).ToString("dd-MM-yy")
today3 = DateTime.Today.AddDays(+3).ToString("dd-MM-yy")
today4 = DateTime.Today.AddDays(+4).ToString("dd-MM-yy")
today5 = DateTime.Today.AddDays(+5).ToString("dd-MM-yy")
today6 = DateTime.Today.AddDays(+6).ToString("dd-MM-yy")
today7 = DateTime.Today.AddDays(+7).ToString("dd-MM-yy")
today8 = DateTime.Today.AddDays(+8).ToString("dd-MM-yy")
today9 = DateTime.Today.AddDays(+9).ToString("dd-MM-yy")
For y = 3 To 9
fiday = CInt(e.Row.Cells(y).Text)
Integer.TryParse(e.Row.Cells(y).Text, fiday)
If fiday > 44.9999999999999 Then
e.Row.Cells(y).Attributes.Add("Style", "background-color: red;")
e.Row.Cells(y).ForeColor = Color.Black
End If
Next
If (e.Row.RowType = DataControlRowType.Header) Then
e.Row.Cells(0).Visible = False
e.Row.Cells(3).Text = today
e.Row.Cells(4).Text = today1
e.Row.Cells(5).Text = today2
e.Row.Cells(6).Text = today3
e.Row.Cells(7).Text = today4
e.Row.Cells(8).Text = today5
e.Row.Cells(9).Text = today6
e.Row.Cells(10).Text = today7
e.Row.Cells(11).Text = today8
e.Row.Cells(12).Text = today9
End If
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Cells(0).Visible = False
If e.Row.Cells(13).Text > "0" Then
e.Row.Cells(13).Attributes.Add("Style", "background-color: red;")
e.Row.Cells(13).ForeColor = Color.Black
End If
For x = 3 To 12
If e.Row.Cells(x).Text = 0 Then
e.Row.Cells(x).Text = "Rest"
End If
Next
End If
End Sub
End Class
碼(.ASPX):
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="FI7DayReport.aspx.vb" Inherits="WebApplication1.FI7DayReport" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="110%" style="font-size: large; text-align: center;"
CellPadding="5" ForeColor="#333333" GridLines="None"
HorizontalAlign="Center"
DataSourceID="SqlDataSource1" onrowdatabound="GridView1_RowDataBound"
AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Payroll" HeaderText="Payroll"
SortExpression="Payroll" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Depot" HeaderText="Depot"
SortExpression="Depot" />
<asp:BoundField DataField="DateToday" HeaderText="DateToday"
SortExpression="DateToday" />
<asp:BoundField DataField="DateToday1" HeaderText="DateToday1"
SortExpression="DateToday1" />
<asp:BoundField DataField="DateToday2" HeaderText="DateToday2"
SortExpression="DateToday2" />
<asp:BoundField DataField="DateToday3" HeaderText="DateToday3"
SortExpression="DateToday3" />
<asp:BoundField DataField="DateToday4" HeaderText="DateToday4"
SortExpression="DateToday4" />
<asp:BoundField DataField="DateToday5" HeaderText="DateToday5"
SortExpression="DateToday5" />
<asp:BoundField DataField="DateToday6" HeaderText="DateToday6"
SortExpression="DateToday6" />
<asp:BoundField DataField="DateToday7" HeaderText="DateToday7"
SortExpression="DateToday7" />
<asp:BoundField DataField="DateToday8" HeaderText="DateToday8"
SortExpression="DateToday8" />
<asp:BoundField DataField="DateToday9" HeaderText="DateToday9"
SortExpression="DateToday9" />
<asp:BoundField DataField="CountExceed" HeaderText="Exceedance Count"
SortExpression="CountExceed" />
<asp:BoundField DataField="AvgFI" HeaderText="Avg FI" SortExpression="AvgFI" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MelPerfTableConString %>"
SelectCommand="SELECT * FROM [FI_7DayReport2]">
</asp:SqlDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
</asp:Content>
可能剛剛對它進行了排序...現在進行測試。 – JamieB