我正在使用更新面板并将SqlDataSource和GridView放在contenttemplate中
我将timercontrol设置为asyncpostback触发器但是当我从sqlserver中的相关表中更改记录时gridview不会更新加上看起来更加疯狂的是当我执行时删除的记录仍显示在网格视图中刷新(完整的帖子页面后面) 此外,我已禁用数据源的缓存,但这不是帮助!!!!!
这是我的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<div id="ajx">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:busConnectionString %>"
SelectCommand="SELECT * FROM [reserv]" EnableCaching="false" CacheDuration="0" CacheExpirationPolicy="Absolute" EnableViewState="false"></asp:SqlDataSource>
</div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="SeatNo" HeaderText="SeatNo"
SortExpression="SeatNo" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
</Columns>
</asp:GridView>
</div>
<div>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
</div>
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1"/>
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
答案 0 :(得分:1)
您必须在计时器的每个刻度上手动对数据源和gridview进行数据绑定 将以下内容添加到Timer1_Tick事件中:
protected void Timer1_Tick(object sender, EventArgs e)
{
SqlDataSource1.DataBind();
GridView1.DataBind();
}