Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 16th, 2006, 07:16 AM
Registered User
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in Reload a GridView using Timer


I am new to ASP.net. I have a problem; I need to reload a gridview for every five seconds. So, I am using a timer control. In the timerconrol_elapsed event, I am getting the datasource from the database and binding it into the gridview. The problem is, the retrieved data from th database is not displaying in the gridview. Here is my code,


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<atlas:ScriptManager EnablePartialRendering="true" ID="UpdateManager" runat="server"></atlas:ScriptManager>
    <form id="form1" runat="server">

    <atlas:UpdatePanel ID="upCityPanel" runat="server" Mode="Conditional">
            <asp:GridView ID="GrdCity" runat="server" PageSize="5"></asp:GridView>
            <atlas:ControlEventTrigger ControlID="btn" EventName="Click" />
    <asp:Button runat="server" ID="btnReload" Text="Click to Reload" OnClick="ReloadGrid" />


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Timers;

public partial class _Default : System.Web.UI.Page
    SqlConnection conn = new SqlConnection("server=localhost/;database=new;user id=sa;password=;");

    protected void Page_Load(object sender, EventArgs e)
        Timer timer = new Timer();
        timer.Enabled = true;
        timer.Interval = 5000;
        timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);

    void timer_Elapsed(object sender, ElapsedEventArgs e)
        ReloadGrid(this, EventArgs.Empty);

    protected void ReloadGrid(object sender, EventArgs e)
        SqlDataAdapter da = new SqlDataAdapter("select distinct(city) from authors", conn);
        DataTable dt = new DataTable();
        if (dt != null)
        GrdCity.DataSource = dt;


Can anyone tell me what should I need to do? for getting the proper output.

Thanks in advance.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reload page Tooltip not work - Reload xslt file? ismailc XSLT 10 January 22nd, 2008 10:03 AM
reload/refresh problem notChavez PHP How-To 23 January 16th, 2007 06:21 AM
Timer Problem gaurav_jain2403 ASP.NET 1.x and 2.0 Application Design 11 February 18th, 2006 09:37 PM
Problem w/ session var being incremented on reload Storm ASP.NET 1.0 and 1.1 Basics 0 October 13th, 2004 01:42 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.