Asp.net网格视图填写Jquery导致错误警报我的代码附加?

时间:2013-02-07 09:51:19

标签: javascript jquery asp.net web-services gridview

嗨我试图用jquery填充网格,但它是警告错误我的webservice代码适合获取数据,因为我之前尝试通过webservice返回字符串,但当我尝试填充数据网格导致错误,即使它没有调试webservice因为它没有解雇它?

首先我在我的代码中使用网格,

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

然后我在代码后面的表上创建行,

   private void BindColumnToGridview()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("user_Id");
            dt.Columns.Add("user_Fullname");
            dt.Columns.Add("user_Need");
            dt.Rows.Add();
            gvDetails.DataSource = dt;
            gvDetails.DataBind();
            gvDetails.Rows[0].Visible = false;
        }

  if (!IsPostBack)
            {
                BindColumnToGridview();
            }

然后我从会话中获取id并将其传递给webservice,如下所示,

<script type="text/javascript" language="javascript">
var empId = '<%= Session["UserID"] %>';
</script>
<script type="text/javascript"> 
$(document).ready(function() {
alert(empId);
        $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8",
        url: "ServiceGetUser.asmx/BindDatatable", 
        data: "{'employeeId': '" + empId + "'}",
        dataType: "json", 
        success: function(data) {
        for (var i = 0; i < data.d.length; i++) {
        $("#gvDetails").append("<tr><td>" + data.d[i].user_Id + "</td><td>" + data.d[i].user_Fullname + "</td><td>" + data.d[i].user_Need + "</td></tr>");
        }
        },
        error: function(result) {
        alert("Error");
        } 
        }); 
        }); 

</script>

我的网络服务为,

   [WebMethod]

        public static UserDetails[] BindDatatable(string employeeId)
        {
            DataTable dt = new DataTable();
            List<UserDetails> details = new List<UserDetails>();

            UserSearch us = new UserSearch();
            DataSet ds = new DataSet();
            Connection cs = new Connection();
            ds = cs.CurrentStatus(employeeId);

                    foreach (DataRow dtrow in dt.Rows)
                    {
                        UserDetails user = new UserDetails();
                        user.user_Id = dtrow["user_Id"].ToString();
                        user.user_Fullname = dtrow["user_Fullname"].ToString();
                        user.user_Need = dtrow["user_Need"].ToString();
                        details.Add(user);
                    }

            return details.ToArray();
        }
        public class UserDetails
        {
            public string user_Id { get; set; }
            public string user_Fullname { get; set; }
            public string user_Need { get; set; }
        }

它正在警告id,然后它警告“错误”而不是重新调整webservice甚至不知道什么是错误的???

我已经包含了jquery库,因为它不是因为它

我以此为例,

http://www.aspdotnet-suresh.com/2012/03/bind-data-to-gridview-with-jquery-or.html

希望得到你的建议

0 个答案:

没有答案