【发布时间】:2020-08-21 07:19:25
【问题描述】:
我正在使用 ASP.Net 页面和 Webservices.asmx 网络服务。我需要在我的 HTML 表格中添加分页,但我不知道如何包含它。我尝试了几种方法,但没有成功。如有任何帮助,我将不胜感激。
aspx页面代码
<script type="text/javascript">
$(document).ready(function () {
//$("#btnShowData").click(function () {
$('#todaywork').on('click', function () {
var timeid = $('#View').html();
$.ajax({
url: 'Todayworktime.asmx/Gettodaywork',
data: { user: timeid },
dataType: "json",
method: 'post',
success: function (data) {
var employeeTable = $('#tblEmployee tbody');
var employeehead = $('#tblEmployee thead');
employeeTable.empty();
employeehead.empty();
employeehead.append('<tr>' +
'<th>Username</th>' +
'<th>Date</th>' +
'<th>Total_Time</th>' +
'<th>Task</th>' +
'<th>Select</th>' +
'</tr > ');
$(data).each(function (index, emp) {
employeeTable.append('<tr><td>'
+ emp.Username + '</td><td>' + emp.Date + '</td><td>' + emp.Total_Time
+ '</td><td>' + emp.Task + '</td><td><button type="button" data-id="' + emp.Task + '" class="get_tsk" style="background-color:steelblue;color:white;border:none;">view</button></td></tr>');
});
},
error: function (err) {
alert(err);
}
});
});
});
</script>
我的 asmx 页面代码是
public class Todayworktime : System.Web.Services.WebService
{
[WebMethod, ScriptMethod]
public void Gettodaywork(string user)
{
List<sessionlist> employeelist = new List<sessionlist>();
string CS = ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("Select * from Todaywork where Username='" + user + "' and Date='"+DateTime.Today+"'", con);
// cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
sessionlist employee = new sessionlist();
employee.Id = Convert.ToInt32(rdr["Id"]);
employee.Username = rdr["Username"].ToString();
employee.Date = rdr["Date"].ToString();
employee.Total_Time = rdr["Total_Time"].ToString();
employee.Task = rdr["Task"].ToString();
employeelist.Add(employee);
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(employeelist));
}
}
我使用的类:
public class sessionlist
{
public int Id { get; set; }
public string Username { get; set; }
public string Date { get; set; }
public string Total_Time { get; set; }
public string Task { get; set; }
}
我尝试了很多方法,但我没有得到我期望的结果,那么有人知道如何应用分页吗?
【问题讨论】: