使用ASP.NET中的静默刷新实时将数据加载到网格

时间:2018-03-12 12:09:32

标签: javascript c# asp.net

我正在尝试使用ASP.Net中的静默刷新将实时加载数据实现到网格视图。对于这些东西,我尝试了下面的代码。

我尝试过:

Default.aspx 页面

<script type="text/javascript">

        function EndGetData(arg) {
            document.getElementById("divScroll").innerHTML = arg;
        }
        setTimeout("<%=CallbackRef %>", 100)

    </script>
    <div id="divScroll">
        <asp:GridView ID="Grid" BorderColor="Turquoise" runat="server">
        </asp:GridView>
    </div>

Default.aspx.cs 页面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Default3 : System.Web.UI.Page,ICallbackEventHandler
{

    public string CallbackRef;
    public string _Callback;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsCallback)
        {
            CallbackRef = ClientScript.GetCallbackEventReference(this, "'bindgrid'", "EndGetData", "'asyncgrid'", false);
        }
    }

    public void GetAuditData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");
        DataRow r = dt.NewRow();
        r[0] = "1";
        r[1] = "ABCD";
        DataRow r1 = dt.NewRow();
        r1[0] = "2";
        r1[1] = "XYZD";
        DataRow r2 = dt.NewRow();
        r2[0] = "3";
        r2[1] = "123D";

        dt.Rows.Add(r);
        dt.Rows.Add(r1);
        dt.Rows.Add(r2);

        Grid.DataSource = dt;
        Grid.DataBind();
    }

    public string GetCallbackResult()
    {
        return _Callback;
    }

    public void RaiseCallbackEvent(string eventArgument)//This function aceepts only one argument: That too only String Argument:
    {
        GetAuditData();
        using (System.IO.StringWriter sw = new System.IO.StringWriter())
        {
            Grid.RenderControl(new HtmlTextWriter(sw));
            _Callback = sw.ToString();
        }
    }


}

您能否建议我们或给我一个代码示例,例如https://demos.devexpress.com/aspxgridviewdemos/databinding/Live.aspx

0 个答案:

没有答案