/// <summary>
/// DataTable转为json
/// </summary>
/// <param name="dt">DataTable</param>
/// <returns>json数据</returns>
public static string ToJson(DataTable dt)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
try
{
foreach (DataRow dr in dt.Rows)
{
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
result.Add(dc.ColumnName, dr[dc]);
}
list.Add(result);
}
}
catch (Exception ex)
{
LogInfo logInfo = new LogInfo("", "DataTable转为json", "Utility.cs页面的ToJson", ex);
logInfo.CreateExceptionLogFile(ex);
}
return SerializeToJson(list);
}
//获取TimeSheet整个数据
public void getTimeSheetTable()
{
string guid = Request.QueryString["guid"].ToString();
TimeSheetBLL TimeSheetBLL = new TimeSheetBLL();
DataTable dt=TimeSheetBLL.getTimeSheetTable(guid);
Response.Write(Utility.ToJson(dt));
Response.End();
}
function TimeSheetTable(guid) {
var model = "";
$.ajax(
{
type: "post",
cache: false,
async: false,
url: "../../web/pages/AjaxPages/GetInitDataController.aspx?Actions=getTimeSheetTable&guid=" + guid,
success: function (d, s) {
if (d != null) {
model = $.parseJSON(d);
}
}
});
return model;
}