How to update grid data without page refresh in c#

In c# are you using Timer control and set interval as you want and use update panel for do not refresh page
please see under below design code

 <asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Timer ID="Timer1" runat="server" Interval="10000">
</asp:Timer>
</div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>

<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:DataGrid ID="grvDemo" runat="server" Width="100%" GridLines="Both" HeaderStyle-BackColor="AntiqueWhite"
AutoGenerateColumns="true">
</asp:DataGrid>
</ContentTemplate>
</asp:UpdatePanel>

And Code Side :

using System.Data;
using System.Data.SqlClient;
 
protected void Page_Load(object sender, EventArgs e)
{
BindGrid();

}
public void BindGrid()
{

//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlConnection con = new SqlConnection("Data Source=BITPLUS5\\SqlExpress;Initial Catalog=temp;User ID=sa;pwd=bit123;");

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from chat order by 1";


cmd.Connection = con;

con.Open();
SqlDataReader dr = cmd.ExecuteReader();

grvDemo.DataSource = dr;

grvDemo.DataBind();
}

Ebook Download
View all
Learn
View all