更新我的asp.net用ajax的datagridview而无需刷新页面。(显示实时数据) [英] update datagridview using ajax in my asp.net without refreshing the page.(Display real time data)
问题描述
我需要显示从MS SQL 2005年我看到一些博客推荐Ajax来解决我的问题实时数据。基本上,现在我有我的Default.aspx页面仅只是一种变通方法我可以能够从我的数据库显示的数据。但是,一旦我手动将数据添加到我的数据库没有更新进行。任何建议家伙来解决这个问题?我需要与出刷新页面更新datagridview的。
I need to display a real time data from MS SQL 2005. I saw some blogs that recommend Ajax to solve my problem. Basically, right now I have my default.aspx page only just for a workaround I could able to display the data from my DB. But once I add data manually to my DB there's no updating made. Any suggestions guys to fix this problem? I need to update datagridview with out refreshing the page.
下面是对Default.aspx.cs我的code
Here's my code on Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillDataGridView();
}
protected void up1_Load(object sender, EventArgs e)
{
FillDataGridView();
}
protected void FillDataGridView()
{
DataSet objDs = new DataSet();
SqlConnection myConnection = new SqlConnection (ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString);
SqlDataAdapter myCommand;
string select = "SELECT * FROM Categories";
myCommand = new SqlDataAdapter(select, myConnection);
myCommand.SelectCommand.CommandType = CommandType.Text;
myConnection.Open();
myCommand.Fill(objDs);
GridView1.DataSource = objDs;
GridView1.DataBind();
}
}
在我的Default.aspx code
Code on my Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ajax Sample</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
<Scripts>
<asp:ScriptReference Path="JScript.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="up1_Load">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Height="136px" Width="325px"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
我现在的问题是如何调用或使用ajax.js以及如何编写一个code调用FillDataGridView()在我的Default.aspx.cs页。
My problem now is how to call or use the ajax.js and how to write a code to call the FillDataGridView() in my Default.aspx.cs page.
感谢你们,希望有人能帮助我在这个问题上。
Thank you guys, hope anyone can help me on this problem.
推荐答案
您会发现这是一个很好的指导的这里
You will find a good guide for this here
请参阅code例子<一href="http://www.asp.net/Ajax/Documentation/Live/ViewSample.aspx?sref=UpdatePanelTechnologyOverview1%23UpdatePanelCS.aspx"相对=nofollow>这里
更新: 的http://hubpages.com/hub/Automatic-Refresh-data-on-page-using-AJAX-update-panel
这篇关于更新我的asp.net用ajax的datagridview而无需刷新页面。(显示实时数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!