Hello @everyone
I am trying to append data to html table using jquery ajax in my Asp.Net Webform. The webmethod is working fine and returning a list result. In success method I am binding the data to table rows by using jquery each loop but there it is showing undefined. Please help me getting work around it below is my code.
$('#txtDate').change(function () {
$.ajax({
type: "POST",
url: "ManPowerEntry.aspx/getData",
contentType: "application/json",
data: JSON.stringify({ projectCode: $('#ddlProject').val(), date: $('#txtDate').val() }),
dataType: "json",
success: function (result) {
alert("success");
$('#gridManpower').children('tr:not(:first)').remove();
var count = 1;
$(result).each(function (index, value) {
$('#gridManpower').append("<tr><td>" + count + "</td><td>" + value.empName + "</td><td>"
+ value.empName +
"</td><td><i class='fa fa-pencil' id='iEdit' style='color:purple; font-size:20px;'></i> | <i class='fa fa-trash' id='iDelt' style='color:purple; font-size:20px;'></i></td></tr>");
count++;
});
},
error: function ajaxError(result) {
alert(result.status + ' : ' + result.statusText);
}
});
});
[WebMethod]
public static List<ProjectManPowerDetails> getData(string projectCode, string date)
{
string query = "select pd.empCode, pd.amount from tbl_ManPowerProject_details pd inner join tbl_ManPowerProject_Master pm on pm.id = pd.project_Id where pm.projectCode = '"+projectCode+"' and pm.assignedDate = '"+date+"'";
DataTable dt = SqlConn.SqlExce.fillDataTableRet(query);
List<ProjectManPowerDetails> lst = new List<ProjectManPowerDetails>();
foreach (DataRow dr in dt.Rows)
{
lst.Add(new ProjectManPowerDetails
{
//Id = Convert.ToInt32(dr["Id"]),
empName = dr["empCode"].ToString(),
amount = Convert.ToDecimal(dr["amount"])
});
}
return lst;
}