此页面是从其他网页重定向的结果,并且在网址中包含公司ID
System.gc()
服务器端代码: //服务器端在app_code文件夹中有一个类来执行其中的每个函数
<script type="text/javascript">
var url = window.location.search.substring(1);
var CID = url.split("=")[1];//here i take the company id from the link
$.ajax({
type: "POST",
url: "CompanyPage.aspx/ajaxBindData",
contentType: "application/json;charset=utf-8",
data: '{CID: ' + JSON.stringify(CID) + '}',
dataType: "json",
success: function (data) {
alert(data.d);
$("#GridView1").data = append(data.d);
alert("done appending");
$("#GridView1").bind;
alert("done binding");
},
error: function (exception) {
alert(exception.responseText );
}
});
</script>
editingemployee: //这是我的项目和数据库之间的关系
public static string ajaxBindData(int CID)
{
/*
SqlDataReader rd = EditingEmployee.FillEmps(CompanyID);
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
*/
DataTable dt = EditingEmployee.GetEmps(CID);
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
string json = JsonConvert.SerializeObject(rows);
return json;
}
答案 0 :(得分:0)
请参阅此链接以获取解决方案,它是gridview模板字段绑定方法 http://www.aspforums.net/Threads/122325/Bind-data-to-GridView-with-TemplateField-TextBox-with-jQuery-or-JSON-in-ASPNet/