更新SqlDatabase并在GRIDVIEW Asp.Net中显示 [英] Update SqlDatabase and Display in GRIDVIEW Asp.Net
问题描述
亲爱的朋友,
正在使用Asp.net C#,GRIDVIEW和SqlServer2005.
我已经在Asp.net c#和数据库中创建了一个程序,作为SqlServer2005.
我的SqlServer数据库将每1分钟更新一次数据.因此要在Gridview中显示此数据.
所以我的问题是每隔1分钟我应该用什么来更新我的GRID.
脚本管理器
Updatepanel,内容模板
计时器..
我可以使用计时器吗?否则我可以使用Updatepanel.
请帮帮我.
谢谢
Dear Friends,
Am working on Asp.net C#, GRIDVIEW , SqlServer 2005.
I have Created a program in Asp.net c# and Database as SqlServer 2005.
My SqlServer Database will Update the data for every 1 Minute. So am displaying this data in Gridview.
So my problem is What should i use to update my GRID for every 1 minute.
Script Manager
Updatepanel, Content Template
Timer..
Can i use Timer for this ? or else I can Use Updatepanel.
Please help me.
THANKS
推荐答案
http://www.programmersheaven.com/mb/ASPNET/374342/374342/refreshing-gridview-after-update/ [
请参考以下代码.希望对您有所帮助.:)
另外,您还必须添加脚本管理器.
< asp:updatepanel id ="UpdatePanel1" runat ="server" xmlns:asp =#unknown">
< contenttemplate>
< asp:timer id ="Timer1" runat ="server" interval ="3600" ontick ="Timer1_Tick">
< asp:gridview id ="gvContact" runat ="server" autogeneratecolumns ="False" datakeynames ="ContactID">
DataSourceID ="SqlDataSource1" AllowPaging ="True" AllowSorting ="True">
<列>< asp:boundfield datafield ="ContactID"标头文字="ContactID" readonly ="True" sortexpression ="ContactID"/>
< asp:boundfield datafield ="CompanyName"标头文本="CompanyName" sortexpression ="CompanyName"/>
< asp:boundfield datafield ="ContactName"标头文本="ContactName" sortexpression ="ContactName"/>
< asp:boundfield datafield =地址"标头文本=地址" sortexpression =地址"/>
< asp:boundfield datafield ="City" headertext ="City" sortexpression ="City"/>
受保护的void Timer1_Tick(对象发送者,EventArgs e)
{
gvContact.DataBind();
}Please refer following code. I hope that helps.:)
Also you have to add Script Manager.
<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
<contenttemplate>
<asp:timer id="Timer1" runat="server" interval="3600" ontick="Timer1_Tick">
<asp:gridview id="gvContact" runat="server" autogeneratecolumns="False" datakeynames="ContactID">
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
<columns><asp:boundfield datafield="ContactID" headertext="ContactID" readonly="True" sortexpression="ContactID" />
<asp:boundfield datafield="CompanyName" headertext="CompanyName" sortexpression="CompanyName" />
<asp:boundfield datafield="ContactName" headertext="ContactName" sortexpression="ContactName" />
<asp:boundfield datafield="Address" headertext="Address" sortexpression="Address" />
<asp:boundfield datafield="City" headertext="City" sortexpression="City" />
protected void Timer1_Tick(object sender, EventArgs e)
{
gvContact.DataBind();
}
这篇关于更新SqlDatabase并在GRIDVIEW Asp.Net中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!