Hi alhamd,
Refer below sample.
HTML
<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblTime" runat="server" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="1000" />
</ContentTemplate>
</asp:UpdatePanel>
Namespaces
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData();
}
}
private void BindData()
{
lblTime.Text = "Last Refreshed: " + DateTime.Now.ToString();
DataTable dt = GetData();
DataTable dtFinal = dt.Clone();
dtFinal.Rows.Add(dt.Rows[i].ItemArray);
GridView1.DataSource = dtFinal;
GridView1.DataBind();
}
protected void TimerTick(object sender, EventArgs e)
{
this.BindData();
if (this.GetData().Rows.Count - 1 == i)
{
i = 0;
}
else
{
i++;
}
}
public static int i = 0;
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("No");
dt.Columns.Add("Name");
dt.Columns.Add("Is_Active");
dt.Rows.Add(1, 123, "ABC", "TRUE");
dt.Rows.Add(2, 234, "SKY", "TRUE");
dt.Rows.Add(3, 456, "XYZ", "TRUE");
dt.Rows.Add(4, 567, "PQR", "FALSE");
return dt;
}
Screenshot