【问题标题】:ASP.net webgrid loses jquery hover after sortASP.net webgrid 在排序后丢失 jquery 悬停
【发布时间】:2017-01-07 16:16:54
【问题描述】:

编辑: 似乎当我将@DateTime.Now 在 html 中设置为“ajaxUpdateContainerId”时,单击网格标题时值会发生变化。网格失去了悬停的绑定。

我有一个 WebGrid 对象,使用 WebMatrix Razor C WebPages,在排序时会丢失 jquery toggleClass 声明。这里有一些示例 js 代码可以提供帮助。

function reBindHover(){
    $('#result tbody').on("hover","tr", function(){
        $(this).toggleClass('clickable');
    });
}

$(document).ready(function () {

    reBindHover();   }

我的 .cshtml 页面中的服务器端代码。

var signgrid = new WebGrid(datasignstatus, ajaxUpdateContainerId: "result", 
    //ajaxUpdateCallback: "addCheck", 
    ajaxUpdateCallback: "reBindHover", 
    rowsPerPage: 20);

这需要如何工作,以便在排序后保持悬停?

【问题讨论】:

    标签: jquery asp.net razor


    【解决方案1】:

    执行排序会导致回发,因此您需要在排序后通过调用 reBindHover 来重新绑定 hover 函数。

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        //rest of the code that does the sorting
    
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "reBindHover", "reBindHover();", true);
    }
    

    【讨论】:

    • WebPages Razor WebGrid 与 MVC 有什么不同?
    猜你喜欢
    • 2010-11-06
    • 2012-05-24
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 2012-11-03
    • 1970-01-01
    相关资源
    最近更新 更多