如何使用jQuery将数据绑定到GridView? [英] how to bind data to gridview using jquery?

查看:80
本文介绍了如何使用jQuery将数据绑定到GridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Jquery/JSON将数据库中的数据绑定到gridview,但是我无法实现这一目标.
我找不到错误.
在这种情况下可以帮助我...非常感谢.

这是我的代码

I tried to bind the data from database to gridview using Jquery/JSON but i cant achieve this one .
I can''t find the error.
help me in this context...Help greately appreciated.

Here is my code

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "http://localhost/DNN/TestWebService.asmx/SelectJobs",
            data: "{}",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.d.length; i++) {

                    $("#gvDetails").append("<tr><td>" + data.d[i].CompanyName + "</td><td>"

+ data.d[i].JobTitle + "</td><td>" + data.d[i].JobDescription + "</td><td>" +

data.d[i].Technology + "</td><td>" + data.d[i].Experience + "</td></tr>");
                }
            },
            error: function (result) {
                var data = jQuery.parseJSON(result);
                alert("Error :"+data);
            }
        });
    });
</script>


我的Web服务是TestWebService.vb,如下所示


My webservice is TestWebService.vb as follows

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports Microsoft.ApplicationBlocks.Data

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class TestWebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function
    <WebMethod()> _
    Public Function SelectJobs() As List(Of JobPortal.Modules.SearchJobs.SearchJobsInfo)
        Return JobPortal.Modules.SearchJobs.SearchJobsController.SearchJobs_SelectJobs("Junior Programmer", "Microsoft .NET")
    End Function
End Class


我的gridview如下


My gridview is as follows

<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false">
        <HeaderStyle BackColor="#DC5807" Font-Bold="true" ForeColor="White" />

</asp:GridView>

推荐答案

(document).ready(function(){
(document).ready(function () {


.ajax({ 输入:"POST", contentType:"application/json; charset = utf-8", 网址:"http://localhost/DNN/TestWebService.asmx/SelectJobs", 数据: "{}", dataType:"json", 成功:功能(数据){ 对于(var i = 0; i < 数据. d.length; i ++) { span>
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost/DNN/TestWebService.asmx/SelectJobs", data: "{}", dataType: "json", success: function (data) { for (var i = 0; i < data.d.length; i++) {


("#gvDetails").append("<tr> < td > "+ data.d [i] .CompanyName +"/td < > " + data.d [i] .JobTitle +"/td < > "+ data.d [i] .JobDescription +" < /td > < td > "+ data.d [i].技术+"/td < > ; "+ data.d [i].体验+" < /td > < /tr > ); } }, 错误:函数(结果){ var data = jQuery.parseJSON(result); alert(错误:" +数据); } }); }); < /script >
("#gvDetails").append("<tr><td>" + data.d[i].CompanyName + "</td><td>" + data.d[i].JobTitle + "</td><td>" + data.d[i].JobDescription + "</td><td>" + data.d[i].Technology + "</td><td>" + data.d[i].Experience + "</td></tr>"); } }, error: function (result) { var data = jQuery.parseJSON(result); alert("Error :"+data); } }); }); </script>


我的Web服务是TestWebService.vb,如下所示


My webservice is TestWebService.vb as follows

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports Microsoft.ApplicationBlocks.Data

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class TestWebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function
    <WebMethod()> _
    Public Function SelectJobs() As List(Of JobPortal.Modules.SearchJobs.SearchJobsInfo)
        Return JobPortal.Modules.SearchJobs.SearchJobsController.SearchJobs_SelectJobs("Junior Programmer", "Microsoft .NET")
    End Function
End Class


我的gridview如下


My gridview is as follows

<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false">
        <HeaderStyle BackColor="#DC5807" Font-Bold="true" ForeColor="White" />

</asp:GridView>


这篇关于如何使用jQuery将数据绑定到GridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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