hi sir,
i have run below code. my database save status as (0,25,50,75,100)
i want that if my status is 0 it should show DOWN in gridview otherwise it should show UP.
Ipaddress pingtime ipstatus
192.38.89.10 june 7 2021 4pm 100
192.183.67.18 june 7 2021 4am 75
192.67.27.90 june 8 2021 5am 0
192.168.578.44 june 9 2021 1.00am 50
I want to display in my webpage in gridview like this
Ipaddress pingtime ipstatus
192.38.89.10 june 7 2021 4pm up
192.183.67.18 june 7 2021 4am up
192.67.27.90 june 8 2021 5am down
192.168.578.44 june 9 2021 1.00am up
my code is here
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="showdataGV" runat="server" align ="center" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="10" Height="589px" OnSelectedIndexChanged="showdataGV_SelectedIndexChanged" Width="926px">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="Black" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066"/>
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</div>
</form>
</body>
C#
namespace NodesDetails
{
public partial class shownodes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
showdata();
}
}
protected void showdata()
{
String cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection con= new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT t.ipaddress,t.pingtime,t.ipstatus,t1.name FROM (SELECT ROW_NUMBER() OVER (PARTITION BY (ipaddress) ORDER BY CONVERT(DATETIME,[pingtime],103) DESC) Row_No,* FROM record GROUP BY ipaddress,pingtime,ipstatus)t INNER JOIN allnodes t1 ON t.ipaddress = t1.ipaddress WHERE Row_No = 1 ", con);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows==true)
{
showdataGV.DataSource = dr;
showdataGV.DataBind();
}
}
}
}
}
PLEASE help me sir.