嗨,我试图用 jquery 填充网格,但它会发出警报错误开火???
首先我在我的代码中使用网格作为,
<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,之后它会警告“错误”并且不调试 web 服务,甚至不知道出了什么问题???
我已经包含了 jquery 库,因为它不是因为它
我得到这个作为例子,
http://www.aspdotnet-suresh.com/2012/03/bind-data-to-gridview-with-jquery-or.html
希望您的建议