【问题标题】:Bind GridView via jQuery ajax通过 jQuery ajax 绑定 GridView
【发布时间】:2009-03-31 00:50:16
【问题描述】:

我是 jQuery 新手,尝试使用 jQuery 填充 GridView 或 Telerik RadGrid。不知道如何去做,也找不到任何例子。任何帮助表示赞赏。谢谢。

基本上我正在尝试显示一个带有文本框和按钮的模式窗口。用户输入搜索条件按下按钮,同一模态窗口中的 gridview 将填充结果。

在网格中选择记录的用户按下另一个按钮,选定的用户被插入到数据库表中,模式窗口关闭,父页面上的网格刷新显示新添加的用户。

<input type="button" id="btnAddNewUserj" value="Add New User" />

$(document).ready(function() {
$("#btnAddNewUserj")
    .click(function() { ShowNewUserDialog(); return false });

$("#btnSearch")
    .click(function() { FindUsers(); return false });
});

function ShowNewUserDialog() {
    $("#newuserDialog").dialog({ modal: true, bgiframe: true }).dialog("open");
}

function FindUsers() {
  // HOW TO DO THIS?
  // Show selectable list of users from the database in grid.
}

<div id="newuserDialog" title="Add New User" style="display:none;">
<div>
<input id="txtSearchFor" type="text" />&nbsp;&nbsp;
<input id="btnSearch" type="button" value="Search" class="Button" /></div>
<p> DISPLAY RESULTS HERE </p>
<div style="margin:10px 6px;">
<input type="button" id="btnjAdd" value="Add" class="Button" />&nbsp;&nbsp;
<input type="button" id="btnjCancel" value="Cancel" class="Button" />   
</div>
</div>

【问题讨论】:

    标签: asp.net jquery ajax gridview


    【解决方案1】:

    这里有几个想法。您不能使用 jQuery 填充 GridView 或 Telerik Grid。 jQuery 是一种客户端技术,而这两个网格是服务器端。

    您可以使用 jQuery 访问 Web 服务并使用结果构建 HTML 表格(这基本上是 GridView 所做的)。

    不过,我猜,您最好只使用本机 GridView 数据绑定。如果要防止完全回发,可以在网格周围使用 .Net UpdatePanel。

    【讨论】:

      【解决方案2】:

      我认为 Telik 不是答案。

      【讨论】:

        【解决方案3】:

        使用 telerik radgrid 的客户端绑定,例如:http://demos.telerik.com/aspnet-ajax/grid/examples/clientbinding/defaultcs.aspx

        请注意,该示例显示了如何绑定到 WCF Web 服务和 ADO.NET 数据服务。周围还有其他样品。

        绑定的其他变体:http://demos.telerik.com/aspnet-ajax/grid/examples/client/declarativedatabinding/defaultcs.aspx

        有关客户端绑定的更多信息:http://demos.telerik.com/aspnet-ajax/grid/examples/client/databinding/defaultcs.aspx

        【讨论】:

        • telerik 很痛苦,请确保您在深入了解该控件之前非常了解
        • @Abu 我同意 Telerik 很痛苦,因为我得到的问题是 OP 已经在使用 Telerik 的控件。根据上下文,答案是正确的,特别是与基于回发的 gridview + 更新面板相比(因为它包括一堆额外的元素,这些元素会给请求增加大量不必要的开销)。有更好的方法,只是如果已经有一些 Telerik 网格就没有那么简单了。
        • 我很抱歉我没有注意到他已经在使用 Telerik 控制 :)
        猜你喜欢
        • 1970-01-01
        • 2023-03-20
        • 2015-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多