I want to add image as condition If Network latency(ms) is ZERO then red image display if Network latency(ms) more then one then green image should be display.
Please help me to do this.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lan.aspx.cs" Inherits="pingtest.lan" %>
<link href="css/StyleSheet2.css" rel="stylesheet" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body style="width: 626px; height: 225px">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="center">
<div class="rounded_corners" style="width: 776px; margin-center: 0px;">
<caption>
</div>
<td class="auto-style2">
<asp:Label ID="lblTime" runat="server" Style="color: #FFFFFF; font-weight: 500; text-align: right; font-size: medium;" />
</td>
</tr><asp:GridView ID="GridView1" runat="server" Width="559px"></asp:GridView>
</caption>
<asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="100" />
</ContentTemplate>
</asp:UpdatePanel>
<div>
<style type="text/css">
.blink { background: yellow; -webkit-transition: backgroundColor 0.05s ease-in-out; -ms-transition: backgroundColor 0.05s ease-in-out; transition: backgroundColor 0.05s ease-in-out; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=gvData] tr:not(:has(th)) td').each(function () {
$('[id*=gvData] tr:not(:has(th))').removeClass('blink');
var data = $(this).text().trim();
if (data.indexOf(' ') != -1) {
var row = $(this).closest('tr');
var backgroundInterval = setInterval(function () {
$(row).toggleClass("blink");
}, 500)
}
});
});
</script>
</form>
</body>
</html>
namespace pingtest
{
public partial class lan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = "Last Refreshed: " + DateTime.Now.ToString();
DataTable pingResults = new DataTable();
pingResults.Columns.AddRange(new DataColumn[] {
new DataColumn("IP", typeof(string)),
new DataColumn("Location",typeof(string)),
new DataColumn("Network latency(ms)",typeof(string)),
new DataColumn("Message",typeof(string))});
// new DataColumn("Status",typeof(string))});
//flage 1
try
{
pingResults.Clear();
List<Employee> employees = GetDetails();
for (int i = 0; i < employees.Count; i++)
{
string address = employees[i].ipAddress;
long time = PingAddress(address, 1);
Ping ping = new Ping();
PingReply pingReply = ping.Send(employees[i].ipAddress);
string message = (pingReply.Status == IPStatus.Success) ? "~/img/grn.jpg" : "~/img/red-circle-icon-16.png";
lock (pingResults.Rows.SyncRoot)
{
// pingResults.Rows.Add(employees[i].ipAddress, employees[i].Emp_Name, time);
pingResults.Rows.Add(employees[i].ipAddress, employees[i].Emp_Name, time, message);
}
Thread.Sleep(1);
}
GridView1.DataSource = pingResults;
GridView1.DataBind();
}
catch (Exception ex)
{
}
}
//flage 1
public class Employee
{
public string ipAddress { get; set; }
public string Emp_Name { get; set; }
}
//flage 1
private List<Employee> GetDetails()
{
List<Employee> employees = new List<Employee>();
string cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
using (SqlCommand cmd = new SqlCommand("SELECT emp_nm,ip_add FROM nms where flag='1'", con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
employees.Add(new Employee
{
Emp_Name = sdr["emp_nm"].ToString(),
ipAddress = sdr["ip_add"].ToString(),
});
}
con.Close();
}
}
return employees;
}
private static long PingAddress(string address, int timeout)
{
try
{
Ping pingClass = new Ping();
PingReply pingReply = pingClass.Send(address, timeout);
return pingReply.RoundtripTime;
}
catch (Exception e)
{
}
return -1;
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!string.IsNullOrEmpty(e.Row.Cells[3].Text))
{
if (e.Row.Cells[3].Text == "UP")
{
e.Row.Cells[3].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[3].BackColor = System.Drawing.Color.Green;
}
else
{
e.Row.Cells[3].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[3].BackColor = System.Drawing.Color.Red;
}
}
}
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "LAN Importent Location";
cell.ColumnSpan = 10;
row.Controls.Add(cell);
// cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
// cell.Text = "Employees";
// row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#647C90");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
protected void TimerTick(object sender, EventArgs e)
{
lblTime.Text = "Dt:" + DateTime.Now.ToString();
// GridView1.DataBind();
}
}
}