我在更新面板中有一个网格视图,就像这样。
<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秒后刷新面板的JavaScript函数
<script type="text/javascript">
window.setInterval(function () {
__doPostBack('<%= UpdatePanel1.ClientID %>', '');
}, 5000);
</script>
问题是当我更改与gridview绑定的数据时,五秒后没有显示任何更改。可以告诉我我的代码中有什么问题或者在我的代码中添加任何其他附加内容以使gridview在内部更新没有页面重定向的更新面板。
答案 0 :(得分:2)
每次回发时都需要手动更新SqlDataSource。如果它背后没有真正的逻辑,你可以将以下内容添加到Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
.....
if (IsPostBack)
{
SqlDataSource1.DataBind();
GridView1.DataBind();
}
}
如果您希望仅在UpdatePanel执行回发时完成此操作,use this method。