[英]Refresh gridview data in a page present in the server
I have created a asp.net webpage which contains a gridview.I bound the gridview to an access database through the steps the gridview control provides when drag dropped from the toolbox(not from the code). 我创建了一个包含gridview的asp.net网页,通过从工具箱(而不是从代码)拖放拖放时,gridview控件提供的步骤将gridview绑定到访问数据库。 This page is actually in the server.
该页面实际上在服务器中。 When i do an updation in the client(in another webpage)(like:add or delete a record in the database)the gridview does not reflect the changes,though the values in the database are changed.
当我在客户端(在另一个网页中)进行更新时(例如:在数据库中添加或删除记录),尽管数据库中的值已更改,但Gridview不会反映更改。 Only when i refresh in the server the change is seen in the client side.
仅当我在服务器中刷新时,更改才能在客户端看到。 plz help.
请帮助。
You can use asp.net ajax timer control to refresh the page / part of page periodically. 您可以使用asp.net ajax计时器控件定期刷新页面/页面的一部分。 The following example shows you can update server time every 5 second.
以下示例显示您可以每5秒更新一次服务器时间。 Similarly you will update the
GridView
. 同样,您将更新
GridView
。
HTML HTML
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="DateStampLabel" />
</ContentTemplate>
</asp:UpdatePanel>
Code behind 后面的代码
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
thank you all.The below code worked for me: 谢谢大家,下面的代码对我有用:
aspx page: aspx页面:
<asp:Panel ID="Panel2" runat="server" Height="146px" Style="z-index: 100; left: 382px;
position: absolute; top: 247px" Visible="true" Width="235px">
<asp:Label ID="deptlabel" runat="server"
style="z-index: 1; left: 0px; top: 33px; position: absolute" Text="Label"
Visible="False"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Style="z-index: 100; left: -146px;
position: absolute; top: 216px; height: 374px; width: 1024px;" AllowSorting="True"
CellPadding="3" AllowPaging="True" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellSpacing="2">
<Columns>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bid" HeaderText="bid"
SortExpression="bid" />
<asp:BoundField DataField="did" HeaderText="did" SortExpression="did" />
<asp:BoundField DataField="bname" HeaderText="bnme"
SortExpression="bname" />
<asp:BoundField DataField="author" HeaderText="athr"
SortExpression="author" />
<asp:BoundField DataField="price" HeaderText="cost"
SortExpression="price" />
<asp:BoundField DataField="edition" HeaderText="editn"
SortExpression="edition" />
<asp:BoundField DataField="category" HeaderText="ctgry"
SortExpression="category" />
<asp:BoundField DataField="publisher" HeaderText="publsr"
SortExpression="publisher" />
<asp:BoundField DataField="status" HeaderText="stat"
SortExpression="status" />
<asp:BoundField DataField="acpr" HeaderText="acpr" SortExpression="acpr" />
<asp:BoundField DataField="volume" HeaderText="vol"
SortExpression="volume" />
<asp:BoundField DataField="ref" HeaderText="ref" SortExpression="ref" />
<asp:BoundField DataField="pages" HeaderText="pgs" SortExpression="pages" />
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:con %>"
SelectCommand="SELECT DISTINCT * FROM [books] WHERE ([bid] LIKE '%' + @bid + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="deptlabel" Name="bid" PropertyName="Text"
Type="String" />
</SelectParameters> </asp:SqlDataSource>
</asp:Panel>
<asp:Label ID="Label9" runat="server" Font-Size="XX-Large" ForeColor="#C04000" Style="z-index: 102;
left: 492px; position: absolute; top: 256px; width: 678px;"
Text="BOOKS REMOVE"></asp:Label>
default.aspx.cs: default.aspx.cs:
protected void Timer1_Tick(object sender, EventArgs e) { 受保护的void Timer1_Tick(object sender,EventArgs e){
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.