2016-04-06 13 views
0

まず、私がこれまで慣れていたVBA標準から何かをしようとするのは初めてです。ASP.NET(VB)Rowdataboundすべてのデータを整数または小数点ではないテキストとして表示

DBサーバー(SQL Server 10.50.40000)にデータが格納されており、Int/Varchar/decimal (18,2)という名前で保存されています。私はVisual Web Dev 2010を使用してこのデータにアクセスして表示するWebページ(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"> 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
    &nbsp; 

    <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> 
+0

今すぐテストしているかもしれません。 – JamieB

答えて

0

問題は、私は、インポートSQLデータとデータクライアントをdidntの、およびASPネットはちょうどだったということでしたそれをテキスト/文字列データとして扱い、何があったのかわからなくても、 "マーカー"も削除されました。

関連する問題