Usuário com melhor resposta
Atualizar página Dinâmicamente

Pergunta
-
Galera,
Eu sou iniciante em Desenvolvimento Web, gostaria de saber como faço para atualizar automaticamente uma página.
Na verdade, estou carregando um gridview nesta página, porém eu quero que ele atualize o resultado de 30 e 30 segundos, porém não sei como fazer? Alguém pode me ajudar??
Segue código da minha pagina Asp.Net e o meu CodeBehind da página
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <style type="text/css"> .style1 { text-align: left; } </style> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2 class="style1"> VERIFICA TAREFAS COMPE </h2> <asp:GridView ID="dgvDados" runat="server" Width="707px"> </asp:GridView> <!-- <h3> <asp:Button ID="btnAtualizar" cssclass="style1" runat="server" Text="Atualizar" onclick="btnAtualizar_Click" style="font-weight: 700; text-align: center" /> </h3> !--> <script type="text/javascript"> function carregaPag() { window.setInterval("atualizar", 30000) } function atualizar() { window.location.href = window.location.href } </script> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { public void PopulaGrid() { DataSet ds = new DataSet(); SqlConnection conexao = null; try { conexao = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); SqlDataAdapter da; da = new SqlDataAdapter("PERFIL_USUARIOS", conexao); da.SelectCommand.CommandType = CommandType.StoredProcedure; conexao.Open(); da.Fill(ds); dgvDados.DataSource = ds; dgvDados.DataBind(); } catch (Exception) { throw; } finally { conexao.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PopulaGrid(); } } }
Att Allan
Respostas
-
Edson,
Eu agradeço pela força, pois consegui realizar usando o Timer do Asp.Net.
Obrigado!
Att Allan
- Marcado como Resposta Allan Moreira quinta-feira, 26 de abril de 2012 03:11
Todas as Respostas
-
Boa tarde.
De uma olhada neste artigo e veja se lhe ajuda:
Consultoria .NET
ANALISTA DESENVOLVEDOR
Se esta sugestão for útil, por favor, classifique-a como útil.
Se ela lhe ajudar a resolver o problema, por favor, marque-a como resposta.
Blog .Net Descomplicado -
Edson,
Eu agradeço pela força, pois consegui realizar usando o Timer do Asp.Net.
Obrigado!
Att Allan
- Marcado como Resposta Allan Moreira quinta-feira, 26 de abril de 2012 03:11