Hi indradeo,
Refer below code.
HTML
<table border="1" style="width: 73%;">
<tr>
<td class="auto-style5" colspan="2"><strong>CEMS Real Time Generation Data</strong></td>
</tr>
<tr>
<td class="auto-style6">
<asp:GridView ID="GridView1" runat="server" ShowHeader="false" Font-Bold="true" Font-Size="15px" OnDataBound="OnDataBound1"
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="285px" Height="123px">
<RowStyle BackColor="#002514" BorderColor="Red" BorderStyle="None" Font-Names="Calibri" ForeColor="White"></RowStyle>
</asp:GridView>
</td>
<td class="auto-style7">
<asp:GridView ID="GridView2" runat="server" ShowHeader="false" Font-Bold="true" Font-Size="15px" OnDataBound="OnDataBound2"
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="286px" Height="123px">
<RowStyle BackColor="#002514" BorderColor="Red" BorderStyle="None" Font-Names="Calibri" ForeColor="White"></RowStyle>
</asp:GridView>
</td>
</tr>
</table>
Namespaces
using System.Data;
using System.Net;
using System.Drawing;
Code
static string[] lines;
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
string textFromFile = (new WebClient()).DownloadString("file://10.1.150.248/display%20board/STACK1UNIT1.txt");
GridView1.DataSource = GetDataFromText(textFromFile);
GridView1.DataBind();
textFromFile = (new WebClient()).DownloadString("file://10.1.150.248/display%20board/STACK1UNIT2.txt");
GridView2.DataSource = GetDataFromText(textFromFile);
GridView2.DataBind();
}
private DataTable GetDataFromText(string textFromFile)
{
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++)
{
dt.Rows.Add(lines[i]);
}
return dt;
}
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 OnDataBound1(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "UNIT#1";
cell.ColumnSpan = 2;
row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#3AC0F2");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
protected void OnDataBound2(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "UNIT#2";
cell.ColumnSpan = 2;
row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#3AC0F2");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
Output
UNIT#1 |
CO2 11.11 |
NO 594.96 |
SO2 1140.55 |
CO 1.00 |
PM 34.00 |
FLOW 20.57 |
|
UNIT#2 |
CO2 11.11 |
NO 594.96 |
SO2 1140.55 |
CO 1.00 |
PM 34.00 |
FLOW 20.57 |
|