Hi indradeo,
Refer below code.
HTML
<asp:GridView ID="GridView1" runat="server" ShowHeader="false" Font-Bold="true" Font-Size="37px"
RowStyle-Font-Names="Calibri" RowStyle-ForeColor="White" RowStyle-BackColor="#2514"
RowStyle-BorderStyle="None" RowStyle-BorderColor="Red" CellPadding="0"
OnRowDataBound="Gridview1_OnRowDataBound" CssClass="auto-style1" Width="923px">
</asp:GridView>
Namespaces
C#
using System.Data;
using System.Drawing;
using System.Net;
VB.Net
Imports System.Data
Imports System.Drawing
Imports System.Net
Code
C#
static string[] lines;
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
string textFromFile = (new WebClient()).DownloadString("http://10.1.246.41/AAQMS/CEMS/ReadTxtFile/Test.txt");
lines = textFromFile.Split('\n');
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Data", System.Type.GetType("System.String")));
for (int i = 0; i < lines.Length; i++)
{
DataRow dr = dt.NewRow();
dr["Data"] = "" + " " + " " + " " + lines[i] + " " + "MB";
dt.Rows.Add(dr);
dr = dt.NewRow();
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Gridview1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].ForeColor = System.Drawing.Color.White;
string line = e.Row.RowIndex % 2 != 0 ? lines[i] : "";
if (e.Row.RowIndex % 2 != 0)
{
if (line.Length <= 200)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
}
else if (line.Length >= 100 && line.Length <= 0)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Orange;
}
else
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Green;
}
}
i++;
}
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "CEMS Realtime Data UNIT#2";
cell.ColumnSpan = 2;
row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#3AC0F2");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
VB.Net
Shared lines As String()
Private i As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim textFromFile As String = (New WebClient()).DownloadString("http://10.1.246.41/AAQMS/CEMS/ReadTxtFile/Test.txt")
lines = textFromFile.Split(vbLf)
Dim dt As DataTable = New DataTable()
dt.Columns.Add(New DataColumn("Data", System.Type.[GetType]("System.String")))
For i As Integer = 0 To lines.Length - 1
Dim dr As DataRow = dt.NewRow()
dr("Data") = "" & " " & " " & " " & lines(i) & " " & "MB"
dt.Rows.Add(dr)
dr = dt.NewRow()
Next
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
e.Row.Cells(0).ForeColor = System.Drawing.Color.White
Dim line As String = If(e.Row.RowIndex Mod 2 <> 0, lines(i), "")
If e.Row.RowIndex Mod 2 <> 0 Then
If line.Length <= 200 Then
e.Row.Cells(0).BackColor = System.Drawing.Color.Red
ElseIf line.Length >= 100 AndAlso line.Length <= 0 Then
e.Row.Cells(0).BackColor = System.Drawing.Color.Orange
Else
e.Row.Cells(0).BackColor = System.Drawing.Color.Green
End If
End If
i += 1
End If
End Sub
Protected Sub OnDataBound(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal)
Dim cell As TableHeaderCell = New TableHeaderCell()
cell.Text = "CEMS Realtime Data UNIT#2"
cell.ColumnSpan = 2
row.Controls.Add(cell)
row.BackColor = ColorTranslator.FromHtml("#3AC0F2")
GridView1.HeaderRow.Parent.Controls.AddAt(0, row)
End Sub