Wednesday, May 22, 2013

How auto update a DataGrid in 1 seconds without refreshing page in asp.net

<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
        <%--<asp:PostBackTrigger ControlID="btnSubmit" />--%>
    </Triggers>
    <ContentTemplate>
     <asp:Timer runat="server" id="UpdateTimer" interval="2000"  OnTick="Timer1_Tick"  />
                        <asp:GridView Width="100%" ID="gdvListing" runat="server" GridLines="none" BackColor="#E6DCC3" CssClass="Forummainhead"
                            DataKeyNames="ProductId" AutoGenerateColumns="False" AllowPaging="True"
                            OnPageIndexChanging="gdvListing_PageIndexChanging" OnRowDataBound="gdvListing_RowDataBound"
                             CellSpacing="1" CellPadding="2" BorderWidth="0" EmptyDataRowStyle-Font-Bold="true">
                            <HeaderStyle HorizontalAlign="center" CssClass="Grid_HeaderStyle"   />
                            <RowStyle HorizontalAlign="left" CssClass="row0" />
                            <AlternatingRowStyle HorizontalAlign="left" CssClass="row1" />
                            <Columns>
                               <asp:TemplateField HeaderText="Product Name" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                        <a href="ProductAddEdit.aspx?ID=<%#DataBinder.Eval(Container.DataItem, "ProductId") %>" >
                                            <%# DataBinder.Eval(Container.DataItem, "Name")%>
                                        </a>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="User Name" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                         <%# DataBinder.Eval(Container.DataItem, "UserName")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                                 <asp:TemplateField HeaderText="Current bid Amount" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container.DataItem, "CurrentBidAmount")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                                  <asp:TemplateField HeaderText="Bid Min. Amount" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container.DataItem, "BidMinValue")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                                 <asp:TemplateField HeaderText="MRP" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container.DataItem, "MRP")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Sold" HeaderStyle-HorizontalAlign="left">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container.DataItem, "IsSold")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="left" />
                                </asp:TemplateField>
                               
                               
                                </Columns>
                            <PagerSettings Mode="NumericFirstLast" Position="Bottom" />
                            <EmptyDataRowStyle CssClass="row0" Font-Underline="False" HorizontalAlign="center"
                                VerticalAlign="Middle" Width="100%" />
                            <PagerStyle CssClass="form_header" Font-Bold="True" ForeColor="#FFFFFF" HorizontalAlign="Right" />
                        </asp:GridView>   
                        </ContentTemplate></asp:UpdatePanel>

Click Here to view ASPX.CS file code