Hi
I have a problem with write code of Visual Studio (VB).
I would like show data from text file for example 500 or 501 or 1456 or 2300 (benutzermb.txt - one line with value) in Gridview.
If value of text file is below 500 then show text in gridview red, if beetwen 501 and 1499 than fonts colour like orange.
If value is above 1500 than text colur like green.

I have a code below:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default19.aspx.vb" Inherits="Default19" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="refresh" content="10">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ShowHeader="false" Font-Bold="true" Font-Size="37px"
RowStyle-Font-Names="Calibri" RowStyle-ForeColor="White" RowStyle-BackColor="Red"
RowStyle-BorderStyle="None" RowStyle-BorderColor="Red" CellPadding="0" OnRowDataBound="Gridview1_OnRowDataBound">
<RowStyle BackColor="Red" BorderStyle="None" Font-Names="Calibri" ForeColor="White"
BorderColor="Red" HorizontalAlign="Center"></RowStyle>
</asp:GridView>
</div>
</form>
</body>
</html>
Aspx.vp code below
Imports System.IO
Imports System.Data
Partial Class Default19
Inherits System.Web.UI.Page
Dim lastWriteTime As DateTime = File.GetLastWriteTime(Server.MapPath("~/App_Data/benutzermb.txt"))
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
dt.Columns.Add(New DataColumn("Data", System.Type.GetType("System.String")))
Dim dr As DataRow = dt.NewRow()
dr("Data") = "Benutzer" + " " + "wielkość" + " " + "value of text file" + " " + "MB"
dt.Rows.Add(dr)
Dim dr1 As DataRow = dt.NewRow()
dr1("Data") = lastWriteTime
dt.Rows.Add(dr1)
' Bind the results to the GridView
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub Gridview1_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim objStreamReader As New StreamReader(Server.MapPath("~/App_Data/benutzermb.txt"))
Dim arrText As New ArrayList
' Loop through the file and add each line to the ArrayList
Do While objStreamReader.Peek() >= 0
arrText.Add(objStreamReader.ReadLine)
Loop
' Close the reader
objStreamReader.Close()
If objStreamReader.Read = "500" Then
e.Row.Cells(0).BackColor = System.Drawing.Color.Green
e.Row.Cells(0).ForeColor = System.Drawing.Color.White
Else
e.Row.Cells(0).BackColor = System.Drawing.Color.Red
e.Row.Cells(0).ForeColor = System.Drawing.Color.White
End If
End If
End Sub
End Class
Thanks for Your helpful.
Wiktor from Poland :-)