2012-11-14 105 views
1

我有更新面板裏面的網格視圖像這樣。gridview沒有更新更新面板

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
<ContentTemplate> 


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" 
              BorderColor="#D9EFFD" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" 
              Font-Names="Tahoma" Font-Size="8pt" GridLines="Horizontal" Width="100%" ForeColor="#010101" 
              ShowHeaderWhenEmpty="True"> 
              <Columns> 
               <asp:BoundField DataField="MODE_TPT_ENTRY" HeaderText="Balance" SortExpression="MODE_TPT_ENTRY"> 
                <HeaderStyle HorizontalAlign="Left" /> 
                <ItemStyle Font-Bold="True" HorizontalAlign="Left" Width="120px" ForeColor="#035BAC" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="OB" HeaderText="Opening" SortExpression="OB"> 
                <ItemStyle HorizontalAlign="Right" Width="70px" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="ISSUED" HeaderText="Arrival" SortExpression="ISSUED"> 
                <ItemStyle HorizontalAlign="Right" Width="70px" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="UNTARE" HeaderText="UNTARE" SortExpression="UNTARE" Visible="False" /> 
               <asp:BoundField DataField="TARE" HeaderText="Tare" SortExpression="TARE"> 
                <ItemStyle HorizontalAlign="Right" Width="70px" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="BALANCE" HeaderText="Balance" SortExpression="BALANCE"> 
                <ItemStyle HorizontalAlign="Right" Width="70px" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="RRY" HeaderText="Recovery" SortExpression="RRY"> 
                <ItemStyle HorizontalAlign="Right" Width="70px" /> 
               </asp:BoundField> 
               <asp:BoundField DataField="TRANSPORT_NO" HeaderText="TRANSPORT_NO" SortExpression="TRANSPORT_NO" 
                Visible="False" /> 
              </Columns> 
              <FooterStyle BackColor="White" ForeColor="#000066" /> 
              <HeaderStyle BackColor="#D9EFFD" Font-Bold="True" ForeColor="#010101" HorizontalAlign="Right" /> 
              <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> 
              <RowStyle ForeColor="#101010" HorizontalAlign="Right" /> 
              <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> 
              <SortedAscendingCellStyle BackColor="#F1F1F1" /> 
              <SortedAscendingHeaderStyle BackColor="#007DBB" /> 
              <SortedDescendingCellStyle BackColor="#CAC9C9" /> 
              <SortedDescendingHeaderStyle BackColor="#00547E" /> 
             </asp:GridView> 


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" 
               ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" SelectCommand="SELECT * from cms_production"> 
              </asp:SqlDataSource> 
</ContentTemplate> 
</asp:UpdatePanel> 

並且其5秒後刷新面板這樣

<script type="text/javascript"> 
window.setInterval(function() { 
__doPostBack('<%= UpdatePanel1.ClientID %>', ''); 
     }, 5000); 
</script> 

問題的JavaScript函數是,當我在這勢必與gridview的數據改變則沒有變化五秒後示出。任何人都可以告訴我什麼是我的代碼中的問題或任何其他額外的東西添加在我的代碼,使更新面板內更新面板沒有頁面重定向的GridView。

+0

先生我使用Sqldatasource綁定Grid.and在哪裏寫'UpdatePanel1.Update();'? – user1820339

+0

Sir sqldatasource已經在contenttemplate中,並且除了內容模板中的gridview列以外沒有其他代碼 – user1820339

+0

Sir請檢查更新 – user1820339

回答

2

每次回發時都需要手動更新SqlDataSource。如果背後沒有真正的邏輯,你可以在下面的只是添加到您的Page_Load:

protected void Page_Load(object sender, EventArgs e) 
{ 
     ..... 

    if (IsPostBack) 
    { 
     SqlDataSource1.DataBind(); 
     GridView1.DataBind(); 
    } 
} 

如果你想完成這件事,只有當UpdatePanel的執行回發,use this method

+0

我認爲他也必須調用grid.DataBind() –

+0

@AmiramKorach尚未測試它,但您可能是對的。更新。 – Blachshma

+0

是的這工作 – user1820339