从客户方(JavaScript)的在asp.net GridView的刷新 [英] Refresh GridView from ClientSide (Javascript) in asp.net

查看:110
本文介绍了从客户方(JavaScript)的在asp.net GridView的刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了网页上的GridView控件。

I have added the Gridview control on a webPage.

我通过调用删除任何行(一次一个行)的 PageMethod的如下:

I am deleting any row (one row at a time) by calling PageMethod as follow:

    <script type="text/javascript">
      function Delete_Row(){
        PageMethods.DeleteRow(row_id, GetTimeCallback, ErrorHandler, TimeOutHandler);
      }
      GetTimeCallback = function (result) 
      {
         if (result) {
            alert('Row is deleted');
            // I want to refresh the Gridview here
          }
      }
    <script type="text/javascript">

,其中 ROW_ID 是该行的primery键。

where "row_id" is primery key of the row.

这显示警报完美,但不会少了一个删除的行刷新GridView的。

我应该写什么code更新GridView的?

注意:我不想刷新整个页面

It shows the alert perfectly but does not refresh the Gridview with one less deleted row.
what code should i write to Update the gridview?
NOTE: I dont want to refresh entire page.

推荐答案

写的回调功能,以达致这...你可以找到的 http://msdn.microsoft.com/en-us/library/ms178208 和的 http://msdn.microsoft.com/en-us/library/ms178210

Write CallBack Function to acheive this...You can find the Callback Functionality at http://msdn.microsoft.com/en-us/library/ms178208 and http://msdn.microsoft.com/en-us/library/ms178210

编辑: -

   protected void Page_Load(object sender, EventArgs e)
   {
    String cbReference =Page.ClientScript.GetCallbackEventReference(this,
        "arg", "ReceiveServerData", "context");
    String callbackScript;
    callbackScript = "function CallServer(arg, context)" +
        "{ " + cbReference + ";}";
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
        "CallServer", callbackScript, true);

   }


 System.IO.StringWriter strDataGridHtml= new System.IO.StringWriter(); 

 public void RaiseCallbackEvent(String eventArgument)
    {
         string idToBeDeleted=eventArgument;
         //Write deleteCode
         //DataBind the Grid
         HtmlTextWriter htwObject = new HtmlTextWriter(strDataGridHtml);
         GridViewControl.RenderControl(htwObject);
    }        

public String GetCallbackResult()
    {
        return strDataGridHtml.ToString();
    }

现在当你看到这个的 strDataGridHtml 将被发送到JavaScript函数ReceiveServerData ...

Now as you see this strDataGridHtml will be sent to Javascript Function ReceiveServerData...

<script type="text/ecmascript">

    function ReceiveServerData(rValue)
    {   
        document.getElementById("divIDWhichEncapsulategridView").innerHTML = rValue;

    }
  </script>

希望这将有助于you..As我没有,我有你的全$ C $词不能写一个确切......但是这应该给你如何进行一些想法......还请大家经过回调功能,以了解这一功能发挥到淋漓尽致。

Hope this Will Help you..As i don't i have your full code i can't write the exact one...but this should give you some idea on how to proceed...And also please go through the "CallBack" Functionality in order to understand this functionality to the fullest..

这篇关于从客户方(JavaScript)的在asp.net GridView的刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆