Popular Posts

Friday, 8 July 2011

Auto Refresh Grdview in ASP.Net

Coding for Page Source :

<html>
<head runat="server">
    <title>Example of Gridview Auto Refresh</title>
    </head>
<body>
    <form id="form1" runat="server">   
   
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
               
    <div style="text-align: center">
    
        <asp:UpdatePanel ID="updateGrid" runat="server" UpdateMode="Conditional"
            RenderMode="Inline"> 
  <ContentTemplate> 
    <asp:GridView ID="gridAutoUpdate" runat="server" AutoGenerateColumns="False"  > 
        <Columns>
            <asp:BoundField DataField="Temp" HeaderText="Temp" SortExpression="Temp" />
            <asp:BoundField DataField="TempValue" HeaderText="TempValue"
                SortExpression="TempValue" />
        </Columns>
    </asp:GridView> 
    <asp:Button ID="buttonUpdate" runat="server"  OnClick="buttonUpdate_Click" /> 
  </ContentTemplate> 
</asp:UpdatePanel> 
 
       
 
<script type="text/javascript" language="javascript"> 
  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(delayUpdateClick); 
  function delayUpdateClick(sender, args) { 
    button = $get("<%= buttonUpdate.ClientID %>"); 
    setTimeout(function() { button.click(); }, 1000);  
  } 

</script> 
    </div>
    </form>
</body>
</html>


Coding For Class Page :

 protected void buttonUpdate_Click(object sender, EventArgs e)
    {
         FillGrid();
    }

private void FillGrid()
    {
        string sql = "select * from temp";
        DataTable ds = new DataTable();
        ds = fun.GetDataTable(sql, lbl);
        gridAutoUpdate.DataSource = ds ;
        gridAutoUpdate.DataBind();
    }

No comments:

Post a Comment