I have share my code and .txt file.
i have getting mention error.
Server Error in '/' Application.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error:
Line 41: if (e.Row.RowIndex % 2 != 0)
Line 42: {
Line 43: if (Convert.ToInt32(line) <= 500)
Line 44: {
Line 45: e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
|
.text file
Unit#1 |
Unit#2 |
Stack1_unit1 CO2 20.0 Percentage 15-Apr-21 12:00 |
Stack2_unit2 CO2 21.0 Percentage 15-Apr-21 12:00 |
Stack1_unit1 NO 54.0 ppm 15-Apr-21 12:00 |
Stack2_unit2 NO 50.0 ppm 15-Apr-21 12:00 |
Stack1_unit1 SO2 12.0 ppm 15-Apr-21 12:00 |
Stack2_unit2 SO2 13.0 ppm 15-Apr-21 12:00 |
Stack1_unit1 CO 5.0 ppm 15-Apr-21 12:00 |
Stack2_unit2 CO 4.0 ppm 15-Apr-21 12:00 |
Stack1_unit1 PM 15.0 mg/Nm3 15-Apr-21 12:00 |
Stack2_unit2 PM 25.0 mg/Nm3 15-Apr-21 12:00 |
Stack1_unit1 FLOW 100 m/s 15-Apr-21 12:00 |
Stack2_unit2 FLOW 110 m/s 15-Apr-21 12:00 |
<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="760px">
</asp:GridView>
namespace ReadTxtFile
{
public partial class WebForm1 : System.Web.UI.Page
{
static DateTime lastWriteTime;
static string[] lines;
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
lastWriteTime = File.GetLastWriteTime(Server.MapPath("~/App_Data/Test.txt"));
lines = File.ReadAllLines(Server.MapPath("~/App_Data/Test.txt"));
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"] = "Stack1_unit1" + " " + "Percentage " + " " + lines[i] + " " + "MB";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Data"] = lastWriteTime;
dt.Rows.Add(dr);
}
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 (Convert.ToInt32(line) <= 500)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
}
else if (Convert.ToInt32(line) >= 501 && Convert.ToInt32(line) <= 1500)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Orange;
}
else
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Green;
}
i++;
}
}
}
}
}